I am trying to run a simple Scala Hello World program using scala-maven-plugin from the command line in my Ubuntu VM running in Win-7 host OS.
I tried to execute in the following two ways :-
mvn scala:run -DmainClass=com.infoobjects.HelloWorld
Declaring the main class in a launcher tag in pom.xml and then executing mvn scala:run from the command line
But I am getting ClassNotFoundException in either case.
Directory Structure :-
Project > src > main > scala > com > infoobjects > HelloWorld.scala
Thanks in advance.
Here's my pom.xml
<build>
<finalName>sparkplay</finalName>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<configuration>
<launchers>
<launcher>
<id>launcher1</id>
<mainClass>com.infoobjects.HelloWorld</mainClass>
</launcher>
</launchers>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
</plugins>
</build>
your pom.xml has schema's issue : <executions> should not be child of <configuration>. So everything under <executions> is ignored
see Maven Model
Related
I'm using Quarkus with Kotlin and tried to generate Rest clients using this Quarkus extension https://github.com/quarkiverse/quarkus-openapi-generator.
I included the dependency and the mentioned plugin into the pom.xml
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
<version>0.9.0</version>
</dependency>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
When compiling everything gets generated correctly into target/openapi/quarkus/clients_json/api/DefaultApi.java
However, when trying to import the DefaultApi it throws an error that it can't find the class.
I've tried the suggestions from the following post maven can't add files in generated-sources for compilation phase and included
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/gen-java</source><!-- adjust folder name to your needs -->
</sources>
</configuration>
</execution>
</executions>
</plugin>
into the pom.xml as well but it didn't do anything.
Does anyone know how to change the output directory of the generated OpenApi files with Quarkus?
Just an FYI:
I did the following, and it worked
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/openapi</source>
<source>src/gen/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
So we are migrating a Maven project to Bazel. In this project, we generated our Open API documentation from Java annotations and using the swagger-maven-plugin as follows:
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputFileName>swagger</outputFileName>
<outputPath>${project.basedir}/src/main/resources/webroot</outputPath>
<outputFormat>JSON</outputFormat>
<resourcePackages>
<package>com.example.package1</package>
<package>com.example.package2</package>
</resourcePackages>
<prettyPrint>true</prettyPrint>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
Is there a way to generate this file using a Bazel rule?
I have a mixed scala/java project. Why would the following import not work?
This error occurs both in Intellij and more importantly on maven command line using
mvn clean -DskipTests package
Here is the intellij SDK:
Here is the relevant section of the pom.xml showing the java/scala interaction - as recommended by https://davidb.github.io/scala-maven-plugin/example_java.html :
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here is the error from maven command line:
[ERROR] /git/OCspark/tcpclient/src/main/scala/com/pointr/tcp/iotest/package.scala:2: object io is not a member of package com.pointr.tcp.java
[ERROR] import java.io._
[ERROR] ^
Update Based on a comment by # LuisMiguelMejíaSuárez I looked at the java sources. Note that java is not the root of the package hierarchy - which might have then been the more obvious cause of this problem:
But .. unmarking_ the java directory as sources does fix the problem..
Why would this fix it?
Seems that something has changed in the scala maven repository cause I get a new error for a project that worked before. If I am running on my own machine it will work since I have .m2 folder that has the missing jar, but when running on a new machine (circle ci) it fails.
LOG:
ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.0.0:compile (scala-compile) on project my-project-name: Execution scala-compile of goal net.alchim31.maven:scala-maven-plugin:4.0.0:compile failed: For artifact {org.scala-sbt:compiler-bridge_2.11:null:jar}: The version cannot be empty. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
The pom looks as follows:
<!-- scala plugins -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<!--<recompileMode>incremental</recompileMode>-->
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
I think this is a new issue - if someone has a workaround I will appreciate
Problem was fixed by adding version to maven plugin:
<!-- scala plugins -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.0.2</version>
<!--<recompileMode>incremental</recompileMode>-->
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<execution>
......
.......
</executions>
</plugin>
"Added version tag"
I hav encountered the same problem, Thanks Ehud Lev for sharing his solution.
I have difficulties with configuring Cobertura code-coverage tool in Jenkins to work with mixed Java/Scala project. Java classes works ok, but Cobertura don't analyze Scala tests.
Scala-specific configuration in my pom.xml:
<version.scala.plugin>3.1.0</version.scala.plugin>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check/>
</configuration>
<version>2.5.2</version
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<!--suppress MavenModelInspection -->
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<!--suppress MavenModelInspection -->
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
It works. It was some kind of proxy issue, once I made build healthy again and built it several times, correct code-coverage appeared.