I've been working in Java Eclipse with a Maven project for school. I've been using Eclemma for code coverage data, but my professor wants to run my code from the command line and get a code coverage report from there. I've been trying to get Jacoco to work, but I really have never worked with Maven or Pom.xmls before and am pretty lost. Thise is what mine looks like at the moment
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId> yada yada yada </groupId>
<artifactId> yada yada yada </artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>0.8.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass> yada yada yada </mainClass>
</configuration>
<executions>
<execution>
<id>run-selenium</id>
<phase>integration-test</phase>
<goals><goal>java</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<!-- nothing -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When I execute
$> mvn clean test jacoco:report
or just jacoco:report, I get
[INFO] --- jacoco-maven-plugin:0.8.1:report (default-cli) # MyFileLocation ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Not sure what to do at this point...
Check plugins
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.0.905</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Add only This plugins
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
To record coverage using JaCoCo you need to execute tests with JaCoCo Java agent.
According to https://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html :
Prepares a property pointing to the JaCoCo runtime agent that can be passed as a VM argument to the application under test.
By default it sets property argLine which is picked by maven-surefire-plugin, however seems that you are not actually using maven-surefire-plugin and instead using java goal of exec-maven-plugin, which
first of all doesn't start new JVM - see https://www.mojohaus.org/exec-maven-plugin/java-mojo.html :
Executes the supplied java class in the current VM
second - doesn't use argLine
So make sure that JaCoCo agent is used during your tests, e.g. use exec goal of exec-maven-plugin and pass argLine to it - see https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html#arguments
Related
I'm using the copy-rename-maven-plugin during the package phase to first copy the jar that I just generated to another directory, then using launch4j-maven-plugin I'm generating exes that wrap the jar and then I need to rename one of the exes (to scr), so, I'm using copy-rename-maven-plugin again.
The problem is that all copy-rename-maven-plugin executions are run together, before launch4j-maven-plugin, so, the second execution fails.
How do define the order of executions? I'm happy creating more phases if that's what's necessary, but creating a Maven plugin seemed a bit of an overkill.
A simplified example of what's going with my pom.xml would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>tech.projecx</groupId>
<artifactId>projecx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the just-built projecx jar to targte/win32/jars -->
<id>copy-jar-for-exe</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/win32/jars/${project.build.finalName}.jar
</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <!-- Make the exes -->
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution> <!-- Make the screensaver exe -->
<id>wrap-screensaver-as-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<outfile>${project.build.directory}\win32\${screensaverExe}.exe</outfile>
<jar>jars\${project.build.finalName}.jar</jar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the screensaver from the exe to the proper scr -->
<id>rename-screensaver-to-scr</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/win32/${screensaverExe}.exe</sourceFile>
<destinationFile>${project.build.directory}/win32/${screensaverExe}.scr</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The order in which executions need to run is this:
copy-jar-for-exe
wrap-screensaver-as-exe
rename-screensaver-to-scr
Any other order doesn't work, but because, I think, copy-jar-for-exe and renamer-screensaver-to-scr are executions from the same plugin, Maven runs it like this:
copy-jar-for-exe
rename-screensaver-to-scr
wrap-screensaver-as-exe
so, it fails.
You could run the copy-jar-for-exe in the prepare-package phase. I beleive you could define both executions in the same plugin configuration but declare the plugin after the launch4j plugin.
Basic idea is, the plugins with executions in the same phase are executed in the order of appearance in the pom. If you bind a single execution to another (earlier) phase, it should be executed before.
I haven't tested this, but I think it should work
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution> <!-- Make the screensaver exe -->
<id>wrap-screensaver-as-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<outfile>${project.build.directory}\win32\${screensaverExe}.exe</outfile>
<jar>jars\${project.build.finalName}.jar</jar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>copy-jar-for-exe</id>
<phase>prepare-package</phase> <!-- run this execution before package phase -->
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/win32/jars/${project.build.finalName}.jar
</destinationFile>
</configuration>
</execution>
<execution>
<id>rename-screensaver-to-scr</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/win32/${screensaverExe}.exe</sourceFile>
<destinationFile>${project.build.directory}/win32/${screensaverExe}.scr</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
I migrated to cloud endpoints v2 following the migration document and v2 example from git repo (https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine/endpoints-frameworks-v2). However, I am not sure on how to set jvmFlag(s) to specify additional properties like backend_store, port, enable debug etc like the it was in v1.
Here is the build tag from my pom.xml.
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId>
<version>2.1</version> <executions> <execution> <phase>compile</phase> <goals>
<goal>display-dependency-updates</goal> <goal>display-plugin-updates</goal>
</goals> </execution> </executions> </plugin> -->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<devserver.storagePath>/Users/user/Documents/development/health/local_db.bin</devserver.storagePath>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>endpoints-framework-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<!-- plugin configuration -->
<hostname>amplified-lamp-688.appspot.com</hostname>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.6.2</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<!--<enableJarClasses>false</enableJarClasses>-->
<!--<!– Comment in the below snippet to bind to all IPs instead of just-->
<!--localhost –>-->
<!--<!– address>0.0.0.0</address> –>-->
<!--<port>8080</port>-->
<!--<!– Comment in the below snippet to enable local debugging with a remove-->
<!--debugger like those included with Eclipse or IntelliJ –>-->
<!--<jvmFlags>-->
<!--<jvmFlag>-Xdebug</jvmFlag>-->
<!--<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>-->
<!--<jvmFlag>-Ddatastore.backing_store=/Users/user/Documents/development/health/local_db.bin</jvmFlag>-->
<!--<jvmFlag>-Ddatastore.default_high_rep_job_policy_unapplied_job_pct=10</jvmFlag>-->
<!--</jvmFlags>-->
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Please help with configuring the jvmFlags.
This is one of the solution to specify jvmFlags
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<!--<devserver.storagePath>/Users/user/Documents/development/health/local_db.bin</devserver.storagePath>-->
<devserver:port>8181</devserver:port>
<devserver.jvmFlags>-Xdebug</devserver.jvmFlags>
<devserver.jvmFlags>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</devserver.jvmFlags>
<devserver.jvmFlags>-Ddatastore.backing_store=/Users/user/Documents/development/health/local_db.bin</devserver.jvmFlags>
</configuration>
</plugin>
I am having an issue migrating from Adobe Flex 3.3.0.4852 to 4.5.1.21328
Applying the same configuration I had it set up it throws a exception executing flexmojos-maven-plugin
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleFiles>
<module>APP_MIGRATED.mxml</module>
</moduleFiles>
<locales>
<param>en_US</param>
</locales>
<services>${basedir}/src/main/resources/services-config.xml</services>
<contextRoot>root</contextRoot>
<keepAllTypeSelectors>true</keepAllTypeSelectors>
<output>${basedir}/target/APP_MIGRATED.swf</output>
<targetPlayer>9.0.0</targetPlayer>
</configuration>
</plugin>
The error is triying to compile the source it trows the next error:
[ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\advancedgrids\4.5.1.21328\advancedgrids-4.5.1.21328.swc$defaults.css:[13,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[13,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[14,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[108,-1]
Unexpected character: D. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[112,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\framework\4.5.1.21328\framework-4.5.1.21328.swc$defaults.css:[15,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\mx\4.5.1.21328\mx-4.5.1.21328.swc$defaults.css:[15,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\spark\4.5.1.21328\spark-4.5.1.21328.swc$defaults.css:[15,-1]
{ expected. [WARNING]
C:\Workspaces\aa_Branches\aa_jdk8_upgrade\flex\src\main\flexapp\APP_MIGRATED.mxml:[0,-1]
CSS selector condition type is not supported: ':normalWithPrompt'
[WARNING]
C:\Workspaces\aa_Branches\aa_jdk8_upgrade\flex\src\main\flexapp\APP_MIGRATED.mxml:[0,-1]
CSS selector condition type is not supported: ':disabledWithPrompt'
This is my full pom configuration
<parent>
<artifactId>app-migrated</artifactId>
<groupId>com.appmigrated</groupId>
<version>1.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>flex</artifactId>
<packaging>pom</packaging>
<name>Flex</name>
<build>
<finalName>APP_MIGRATED</finalName>
<sourceDirectory>src/main/flexapp</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${basedir}/target/generated-resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${flex-mojos.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleFiles>
<module>APP_MIGRATED.mxml</module>
</moduleFiles>
<locales>
<param>en_US</param>
</locales>
<services>${basedir}/src/main/resources/services-config.xml</services>
<contextRoot>root</contextRoot>
<keepAllTypeSelectors>true</keepAllTypeSelectors>
<output>${basedir}/target/APP_MIGRATED.swf</output>
<targetPlayer>9.0.0</targetPlayer>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>wrapper</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<ignoreVersionIssues>true</ignoreVersionIssues>
<htmlName>APP_MIGRATED</htmlName>
<outputDirectory>${project.build.directory}/html-wrapper</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-config</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
<includeArtifacIds>APP_MIGRATED</includeArtifacIds>
<includeGroupIds>${project.groupId}</includeGroupIds>
<excludeTransitive>true</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make.html-bundle</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>src/main/assembly/html-bundle.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make.resources</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>src/main/assembly/resources.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<flex.sdk.version>4.5.1.21328</flex.sdk.version>
<flex-mojos.version>4.0-RC2</flex-mojos.version>
</properties>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>${flex.sdk.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.adobe.cairngorm</groupId>
<artifactId>cairngorm</artifactId>
<version>2.2.1</version>
<type>swc</type>
</dependency>
</dependencies>
I know maybe there is can be another errors after this one, but this is the one which concerns me more.
Greetings,
try flexmojos 7 :
<properties>
<flexmojos.version>7.0.1</flexmojos.version>
<flex.version>4.13.0.20140701</flex.version>
<flash.version>16.0</flash.version>
</properties>
plugin look like this
<plugins>
<plugin>
<groupId>net.flexmojos.oss</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${flexmojos.version}</version>
<extensions>true</extensions>
<configuration>
<sourceFile>APP_MIGRATED.mxml</sourceFile>
<compilerWarnings>
<warn-no-constructor>false</warn-no-constructor>
</compilerWarnings>
</configuration>
<dependencies>
<!-- This handles a bug in maven which causes problems with flex resources -->
<dependency>
<groupId>net.flexmojos.oss</groupId>
<artifactId>flexmojos-threadlocaltoolkit-wrapper</artifactId>
<version>${flexmojos.version}</version>
</dependency>
<!-- Without this FM will use the compiler configured in its master
pom, which will result in version conflicts -->
<dependency>
<groupId>org.apache.flex</groupId>
<artifactId>compiler</artifactId>
<version>${flex.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
I have a mixed Scala/Java project that doesn't compile well.
The problem arises when Java code is trying to call Scala code in the same package.
Of course, I have the standard layout:
src/main/java
src/main/scala
src/test/java
src/test/scala
I've looked at other similar Stackoverflow questions but this question is a little outdated. This other question doesn't help either.
I have also followed the scala-maven-plugin documentation page.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</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>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have tried unsuccessfully to follow this blog post.
IDEA project with Scala plugin imported from the pom.xml can compile and run my project successfully.
What is the right way of doing it?
Does the Java code gets compiled twice? First by the Scala plugin and the by the Java plugin?.
Here is a working example of pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>stackoverflow</groupId>
<artifactId>q24448582</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<scala.version>2.10.3</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
</execution>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Problem 1
At first I thought the problem was due to using a modern version of the maven-compiler-plugin. I was using version 3.0 instead of 2.0.2.
The solution has been:
- Remove the maven-compiler-plugin
- Add this setting: incremental
Finally my pom.xml is this:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<configuration>
<recompileMode>incremental</recompileMode>
<args>
<arg>-deprecation</arg>
<arg>-explaintypes</arg>
<arg>-target:jvm-1.7</arg>
</args>
</configuration>
<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>add-source</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Problem 2
Another problem I was experiencing is this:
<dependencies>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-native_${scala.version}</artifactId>
<version>3.2.9</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}.4</version>
</dependency>
</dependencies>
<properties>
<scala.version>2.10</scala.version>
</properties>
This make this solved problem arise:
https://issues.scala-lang.org/browse/SI-5733
Probably it was using an old version of the Scala compiler.
The solution has been to rename scala.version to scala.major, as this property has a special meaning.
In order to get the scala-maven-plugin to respect Java 1.8, but still allow mixed compilation of java and scala, we use this:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<recompileMode>incremental</recompileMode>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
...
I add blow code at pom.xml file <build> block and working good!
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- SCALA AND JAVA MIX COMPILATION -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-shaded-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
...
</pluginManagement>
<resources>
...
</resources>
</build>
No matter how much I do mvn clean install even with -U this dependency (along with some other) is not being coped into the target\app-1.0-SNAPSHOT\WEB-INF\lib folder:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
Not sure why this happens now, when in the pom.xml there is the <packaging>war</packaging>
build
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.version}</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Copies static web files from src/main/webapp to target/${webappDirectory} -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<!-- the exploded goal gets executed during compile phase -->
<phase>compile</phase>
<goals>
<goal>exploded</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${project.artifactId}</warName>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>