I'm working on a maven project, which is built by a jenkins-server. worked fine. But since I'm using the build plugin ( with full dependencies), and changed javaversion to 1.6 its troubling
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.278s
[INFO] Finished at: Wed Oct 02 07:32:07 CEST 2013
[INFO] Final Memory: 17M/141M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving /var/lib/jenkins/workspace/MavenTest/pom.xml to MavenTest/MavenTest/0.0.1-SNAPSHOT/MavenTest-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /var/lib/jenkins/workspace/MavenTest/target/MavenTest-0.0.1-SNAPSHOT.jar to MavenTest/MavenTest/0.0.1-SNAPSHOT/MavenTest-0.0.1-SNAPSHOT.jar
[JENKINS] Archiving /var/lib/jenkins/workspace/MavenTest/target/MavenTest-0.0.1-SNAPSHOT-jar-with-dependencies.jar to MavenTest/MavenTest/0.0.1-SNAPSHOT/MavenTest-0.0.1-SNAPSHOT-jar-with-dependencies.jar
channel stopped
FATAL: hudson.maven.MavenBuild.pickArtifactManager()Ljenkins/model/ArtifactManager;
java.lang.NoSuchMethodError: hudson.maven.MavenBuild.pickArtifactManager()Ljenkins/model/ArtifactManager;
at hudson.maven.MavenBuild$ProxyImpl.performArchiving(MavenBuild.java:455)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:815)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:567)
at hudson.model.Run.execute(Run.java:1604)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:506)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:246)
Where this is my pom:
<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>MavenTest</groupId>
<artifactId>MavenTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>my.maven.example.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
How can I fix this?
//edit:
its jenkins on ubuntu 12.04, native installed.
At first sight it seems to be problem with Hudson jar.
You can try following this:
Bounce hudson server and clean workspace of project, try again.
If that doesn't work and you get same error then try creating a new hudson job and see if it works.
If abve 2 fails then problem is indeed with Hudson jar, replace the jar.
Related
I'm having trouble getting JaCoCo to work with Maven. I keep running into either
Skipping JaCoCo execution due to missing execution data file.
Or
The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.8.2:check are missing or invalid
I also can't seem to get JaCoCo to run with just mvn clean test instead I have to run mvn clean test jacoco:report or mvn clean test jacoco:check
I've tried a variety of methods of editing my POM file, such as adding configuration for destFile and dataFile, as well as the POM settings here: https://howtodoinjava.com/junit5/jacoco-test-coverage/ and here https://www.lambdatest.com/blog/reporting-code-coverage-using-maven-and-jacoco-plugin/ . Any help would be greatly appreciated. Below is my POM file
<?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>com.NAME.PROJECTNAME</groupId>
<artifactId>PROJECTNAME</artifactId>
<version>1.0-SNAPSHOT</version>
<name>PROJECTNAME</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>HelloFX</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
This is because you are using <pluginManagement> tag, and <plugins> are put inside it.
As per the Maven documentation on <pluginManagement>,
pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children or in the current POM. The children have every right to override pluginManagement definitions.
In short, you will use <pluginManagement> in case of multi-module Maven project. Here is a bit more explanation in this answer.
I removed the <pluginManagement> tag from pom.xml and now the build is working and Jacoco report is getting generated.
-> mvn clean verify
...
[INFO] --- jacoco-maven-plugin:0.8.2:prepare-agent (default) # PROJECTNAME ---
[WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
[INFO] argLine set to -javaagent:/home/codejournal/.m2/repository/org/jacoco/org.jacoco.agent/0.8.2/org.jacoco.agent-0.8.2-runtime.jar=destfile=/tmp/maven-jacoco/target/coverage-reports/jacoco-unit.exec
...
...
[INFO] --- jacoco-maven-plugin:0.8.2:report (report) # PROJECTNAME ---
[INFO] Loading execution data file /tmp/maven-jacoco/target/coverage-reports/jacoco-unit.exec
[INFO] Analyzed bundle 'PROJECTNAME' with 1 classes
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) # PROJECTNAME ---
[INFO] Building jar: /tmp/maven-jacoco/target/PROJECTNAME-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.141 s
[INFO] Finished at: 2022-04-24T02:18:30+05:30
[INFO] ------------------------------------------------------------------------
-> cat target/site/jacoco/jacoco.csv
GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED
PROJECTNAME,io.codejournal.maven.jacoco,Hello,7,0,0,0,3,0,2,0,2,0
I am developing a Java agent using ByteBuddy, and I need the ByteBuddy library .jar file to be included in the agent .jar file. So far, in order for the agent to run smoothly, I need the ByteBuddy library .jar files to be present in the classpath both at compile time and at runtime. How can I bundle a .jar file such that the agent is self-contained ?
I tried using the shade plugin (as demonstrated here) as well as a few other techniques found on the web, but none of them seem to really include the dependencies in the .jar file, only a reference.
For every technique, I looked in the resulting .jar file (weighs around 5kB every time) and only found the .class files corresponding to the classes I had written, no class files related to ByteBuddy. To be clear, the ByteBuddy library .jar file weighs about 3MB, so I expect my self-contained agent .jar file to weigh around 3MB, as my code is light.
Below is my pom.xml file :
<?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>com.captainhook.agent</groupId>
<artifactId>agent</artifactId>
<version>1.0-SNAPSHOT</version>
<name>agent</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>bytebuddy</artifactId>
<version>1.12.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/byte-buddy-1.12.3.jar</systemPath>
</dependency>
<dependency>
<groupId>net.bytebuddy.agent</groupId>
<artifactId>bytebuddy-agent</artifactId>
<version>1.12.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/byte-buddy-agent-1.12.3.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
And this is the output I get after running mvn package :
[...]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # agent ---
[INFO]
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) # agent ---
[INFO] Building jar: /home/bluesheet/svn/stages/captainhook/2021/ijp-frida-jdi-bytebuddy/1/dbg/shared/agent/maven-test/agent/target/agent-1.0-SNAPSHOT-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.339 s
[INFO] Finished at: 2021-12-31T12:26:59+01:00
[INFO] ------------------------------------------------------------------------
EDIT:
So, the reason why all the previous techniques were not working was because of the way I specified the dependencies. This doesn't get included :
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>bytebuddy</artifactId>
<version>1.12.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/byte-buddy-1.12.3.jar</systemPath>
</dependency>
while this does :
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.6</version>
</dependency>
I am new to maven so I blindly copy-pasted a piece of code to include the dependencies and I did not spot the error...
Thank you very much !
Sounds like you need to use the "maven-assembly-plugin" with the "jar-with-dependencies" descriptor.
E.g. here is a full example pom file with a dependency on ByteBuddy:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test.example</groupId>
<artifactId>packaging-example</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>test.example.TestByteBuddy</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</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>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.6</version>
</dependency>
</dependencies>
</project>
And for the sake of completeness - here is the main class also :
package test.example;
import net.bytebuddy.ByteBuddy;
public class TestByteBuddy
{
public static void main(String... args) throws Exception
{
System.out.println("Hello Byte Buddy Class - " + ByteBuddy.class);
}
}
Building this will produce an additional file in the target directory - packaging-example-1.0-SNAPSHOT-jar-with-dependencies.jar
Then you should be able to run it simply with :
java -jar packaging-example-1.0-SNAPSHOT-jar-with-dependencies.jar
to give you the output:
Hello Byte Buddy Class - class net.bytebuddy.ByteBuddy
I try to run unit tests when surefire by default skipped tests in pom.xml.
this is my pom.xml surefire configuration :
<?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>org.example</groupId>
<artifactId>jenkins-tutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<skipTests>true</skipTests>
<junit.jupiter.version>5.0.0-M5</junit.jupiter.version>
<junit.vintage.version>4.12.0-M5</junit.vintage.version>
<junit.platform.version>1.0.0-M5</junit.platform.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
ir.moke.jenkins.MyLib
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Test</include>
</includes>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
and i run this command :
mvn clean compile test -DskipTests=false
this is console log:
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # jenkins-tutorial ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/mah454/Programming/java/jenkins-tutorial/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) # jenkins-tutorial ---
[INFO] Tests are skipped.
according to this document:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html
I want to run test in this case .
How can fix this problem ?
Here's my project: https://github.com/mah454/jenkins-tutorial
Rename SampleTestClass in your project to SampleTest and then you can run the command:
mvn test -DskipTests=false
The default name for a test class must end with Test.
Or you can change the includes configuration to:
<includes>
<include>*TestClass</include>
</includes>
This problem happens often, more and more, because the people do not read the documentations, example: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
Pls use the postfix Test and not TestClass in the file name. You can freely use the postfix TestCase but it is already obsolete. If you rely on the defaults, you would NOT use the sections
<includes>
<include>xxx</include>
</includes>
The plugins in CI rely on the default postfixes, no need to reconfigure them!
I am trying to build a Kafka Streams Application that uses lambda expressions.
My maven build configuration is mvn clean install
When I do RunAs > Maven build, I get the following error:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/junaid/eMumba/StreamsExample/streams.examples/src/main/java/myapps/Pipe.java:[53,38] lambda expressions are not supported in -source 1.5
(use -source 8 or higher to enable lambda expressions)
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.265 s
[INFO] Finished at: 2018-02-24T14:50:04+05:00
[INFO] Final Memory: 11M/150M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project streams.examples: Compilation failure
[ERROR] /home/junaid/eMumba/StreamsExample/streams.examples/src/main/java/myapps/Pipe.java:[53,38] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
In Java Build Path I have JRE System Library [JavaSE 1.8].
In Preferences > Java > Installed JREs I have java-8-openjdk
This is my pom.xml:
I have added the org.apache.maven.plugins: maven-compiler-plugin dependency at the end.
<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>streamsexamples</groupId>
<artifactId>streams.examples</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>Kafka Streams Quickstart :: Java</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kafka.version>1.0.0</kafka.version>
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<!-- Execute "mvn clean package -Pbuild-jar" to build a jar file out of
this project! -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
myapps.Pipe
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Apache Kafka dependencies -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>${kafka.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
</project>
What can I do to resolve this?
Try to add the source and target version to your pom:
<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>
</plugins>
See https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
Use this pom.xml. Specify the source and target versions for maven-compiler-plugin.
<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>streamsexamples</groupId>
<artifactId>streams.examples</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>Kafka Streams Quickstart :: Java</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kafka.version>1.0.0</kafka.version>
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<!-- Execute "mvn clean package -Pbuild-jar" to build a jar file out of
this project! -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
myapps.Pipe
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Apache Kafka dependencies -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>${kafka.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
</dependencies>
I am trying to build spring-boot application that uses java-9 and would be deployed to heroku. As a build tool I use maven.
I generated spring boot 1.5 application using initializr. I added heroku specific files and added toolchains.xml to .m2 repository for maven-compiler-plugin.
My pom.xml looks like this
<?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>com.lapots.breed.platform.cloud</groupId>
<artifactId>java-cloud-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>java-cloud-sample</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.9</java.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<maven.compiler.release>9</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<encoding.source>${project.build.sourceEncoding}</encoding.source>
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<configuration>
<toolchains>
<jdk>
<version>1.9</version>
<vendor>oracle</vendor>
</jdk>
</toolchains>
</configuration>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I try to compiler project using mvn clean package I get the error
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] javac: invalid flag: -Xmodule:null
Usage: javac <options> <source files>
use --help for a list of possible options
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.031 s
[INFO] Finished at: 2017-08-30T21:08:25+03:00
[INFO] Final Memory: 20M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile (default-testCompile) on
project java-cloud-sample: Compilation failure
[ERROR] javac: invalid flag: -Xmodule:null
[ERROR] Usage: javac <options> <source files>
[ERROR] use --help for a list of possible options
[ERROR]
[ERROR]
[ERROR] -> [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.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
module-info looks like this
module com.lapots.breed.platform.cloud.javacloudsample {
requires spring.boot;
}
What is the problem? Project available here
github repository
maven-compiler-plugin 3.6.0 is based on the first signature of module-info.class, which has changed a couple of times. It is not compatible with current Java 9 signature. You should use 3.6.2 when using most recent versions of JDK 9.
Looks like your toolchains.xml does not include an entry for Java 9. Try this:
<toolchain>
<type>jdk</type>
<provides>
<version>1.9</version>
<vendor>oracle</vendor>
</provides>
<configuration>
<jdkHome>/path/to/jdk/9</jdkHome>
</configuration>
</toolchain>
Rightly pointed out by #Robert you need to update your maven-compiler-plugin. To add to it, also as stated in the Maven/Jigsaw+9 over the maven plugins. The minimum compatible version of maven-compiler-plugin with current jdk-9+181 is 3.6.2 which can be used as :
<!--Minimum compatible version required-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<jdkToolchain>
<version>9</version>
</jdkToolchain>
</configuration>
</plugin>
And to quote from one of the examples of maven-compiler-plugin with module-info.java here:
For projects that want to be compatible with older versions of Java
(i.e 1.8 or below), but also want to provide a module-info.java for
Java 9 projects must be aware that they need to call javac twice: the
module-info.java must be compiled with release=9, while the rest of
the sources must be compiled with a lower version of source/target.
which can be achieved using (JAVA_HOME set as 1.8.x) :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<!-- compile everything to ensure module-info contains right entries -->
<!-- required when JAVA_HOME is JDK 8 or below -->
<jdkToolchain>
<version>9</version>
</jdkToolchain>
<release>9</release>
</configuration>
</execution>
<execution>
<id>base-compile</id>
<goals>
<goal>compile</goal>
</goals>
<!-- recompile everything for target VM except the module-info.java -->
<configuration>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
<!-- defaults for compile and testCompile -->
<configuration>
<!-- jdkToolchain required when JAVA_HOME is JDK 9 or above -->
<jdkToolchain>
<version>[1.5,9)</version>
</jdkToolchain>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Few things to note there though are:
... you will need at least Maven 3.3.1 to specify a custom
jdkToolchain in your plugin configuration
Or you can also configure the JAVA_HOME as /jdk9/Contents/Home/bin and use the following configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<!-- compile everything to ensure module-info contains right entries -->
<release>9</release>
</configuration>
</execution>
<execution>
<id>base-compile</id>
<goals>
<goal>compile</goal>
</goals>
<!-- recompile everything for target VM except the module-info.java -->
<configuration>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
<!-- defaults for compile and testCompile -->
<configuration>
<!-- Only required when JAVA_HOME isn't at least Java 9 and when haven't configured the maven-toolchains-plugin -->
<jdkToolchain>
<version>9</version>
</jdkToolchain>
<release>6</release>
</configuration>
</plugin>