Generate two jars of same Maven project using different Scala version - scala

I am having a Maven project with Scala code and i want to generate the two jars based on the different Scala versions (2.10.6 and 2.11.8).
If someone please suggest the solution how i can achieve this in single maven install execution or if there is any other way of achieving this in Maven using some Maven plug in.

I am able to solve this problem using multiple executions.
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-version-2.10</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.10.6</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.10</outputDir>
</configuration>
</execution>
<execution>
<id>scala-version-2.11</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.11</outputDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>scala-2.10</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.10</classifier>
<excludes>
<exclude>scala-2.11/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>scala-2.11</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.11</classifier>
<excludes>
<exclude>scala-2.10/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

Create profiles that have dependency overridden for different versions of Scala. You will need to run mvn install on both profiles. For more information see: different-dependencies-for-different-build-profiles-in-maven
Also you need to alter artifact name / version in profiles to make distinction between those two.

Related

Quarkus - Generate rest clients from OpenApi

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>

Scaladoc options with Maven

I'm looking for help with the scala-maven-plugin for Maven. I would like to generate my Scaladoc but I'm having some problems with it.
I actually can create my Scaladoc typing the following command:
mvn scala:doc
The problem now is that I want to add some options when I generate the Scaladoc, such as -no-link-warnings.
Does anyone know how to do this? I have found a way (the code below works), but I don't think that's the way I should be done.
My pom file is:
<build>
...
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<args>
<arg>-no-link-warnings</arg>
</args>
</configuration>
<executions>
<execution>
<id>Compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
EDIT
A better approach has been suggested by the user Tunaki on the first reply, you can see the code there.
Your configuration is entirely correct, although you could write it a bit diffently. Currently (forgetting the part about compiling the sources), you have:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<args>
<arg>-no-link-warnings</arg>
</args>
</configuration>
</plugin>
With such a configuration, you declare that every execution of the scala-maven-plugin will have the additional argument -no-link-warnings. This is because you are declaring it inside the global configuration element. You can have a configuration that is specific to an execution of the plugin, exactly like what you have for the compiling part:
<execution>
<id>Compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
This configuration will only be taken into account when the execution Compile will be invoked.
As such, it would be preferable to change your configuration to be specific to an execution of the plugin, because the argument -no-link-warnings is really specific to generating the Scaladoc.
This would be the final plugin declaration:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>Scaladoc</id>
<goals>
<goal>doc</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<args>
<arg>-no-link-warnings</arg>
</args>
</configuration>
</execution>
<execution>
<id>Compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
Then, when you package your project with mvn package for example, the Scaladoc will be automatically generated with the correct argument.

How can I make scala-maven-plugin recognize Cp1252 encoding?

I have several maven modules that use Cp1252 encoding. I had no trouble with this encoding until I added scala to one of the modules. The scala-maven-plugin ignores the project.build.sourceEncoding property and attempts to parse the source files as if they were UTF-8.
I tried adding the encoding to the plugin configuration:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<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>
<encoding>Cp1252</encoding>
</configuration>
</plugin>
When that didn't work I tried adding the encoding to the executions too:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<sourceDir>${basedir}/scala</sourceDir>
<encoding>Cp1252</encoding>
</configuration>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<sourceDir>${basedir}/scala</sourceDir>
<encoding>Cp1252</encoding>
</configuration>
</execution>
</executions>
<configuration>
<encoding>Cp1252</encoding>
</configuration>
</plugin>
The module in question has 1454 source files, so converting the module to use UTF-8 is not practical.
I used this solution:
<configuration>
<args>
<arg>-encoding</arg>
<arg>${project.build.sourceEncoding}</arg>
</args>
</configuration>
Not sure if it will work for you.
from the doc is for
The -encoding argument for the Java compiler. (when using incremental compiler).
So it should not work in your case (not incremental + not java).
The solution of Gooseman is the right :
<configuration>
<args>
<arg>-encoding</arg>
<arg>${project.build.sourceEncoding}</arg>
</args>
</configuration>

scala code-coverage tool Cobertura on jenkins

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.

Which emma-maven-plugin should I be using?

org.sonatype.maven.plugin:emma-maven-plugin:1.2
org.codehaus.mojo:emma-maven-plugin:1.0-alpha-3
org.apache.maven.plugins:maven-emma-plugin:0.5
Use jacoco - emma in no longer supported. Jacoco supports java 7.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.6.201201232323</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
I'm not sure which one is the best. I do know that there is hardly any documentation on the sonatype plugin (other than this blog). Also I think the apache one is rather old, so personally I would try the codehaus plugin.