I have a Maven project with 3 submodules: 2 of them should be compiled with java8 and one of them with java11. My main JAVA_HOME environment variable when running maven is set to the JDK 8 installed in my machine. I want to specify to use the jdk 11 only for the specific submodule that needs it but I can't make it work.
In the POM father I have the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
In the specific subproject that needs jdk 11 I tried to setup things following this documentation http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html so I have
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_11_HOME}/bin/javac</executable>
</configuration>
</plugin>
and the JAVA_11_HOME variable is set in my settings.xml (according to the doc)
When I run the compilation (either of the whole project or of the single java11 submodule) I get
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project features-serving: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project
features-serving: Compilation failure
If I run with debug and stacktrace enabled I don't get any useful information. Basically I cannot figure out what it is going wrong. Only thing I am sure is that maven is picking up correctly the JDK 11 path from my settings.xml file.
Related
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project AusPost: Compilation failure
[ERROR] javac: invalid flag: -s
[ERROR] Usage: javac
I am not providing any tag to the maven compiler plugin in my pom.xml. Still it is throwing error saying invalid flag -s.
How to get rid of this?
POM.XML ->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
Usually, -s comes for settings.xml of maven, but you have to provide more info in order to understand your question.
I have a solution in IntelliJ that builds fine on my local.
Extract from the POM:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<dependencies>
</dependencies>
</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>
I have installed Jenkins on my local and created a simple Maven project and pointed it to my POM file from within Jenkins.
When I build the solution from Jenkins I get the following error:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error resolving version for 'org.apache.maven.plugins:maven-surefire-plugin': Plugin requires Maven version 2.2.1
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
On Jenkins I have installed:
Maven Integration plugin
2.15.1
Any ideas / advice would be appreciated.
My own silly mistake. Had to specify the Maven and Java JDK under:
Manage Jenkins --> Global Tool Configuration
After this everything worked.
We setup the compiler plugin in a dedicated parent pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
But the javadoc plugin (version 2.9.1) fails with error:
error: lambda expressions are not supported in -source 1.7
If i run with "-X" i only see that indeed source is set to 1.7: source = 1.7
So the question is why?
(the normal build works fine!)
I also tried to explicitly set source either by property maven.compiler.source or by plugin configuration - i put the compiler plugin configuration from above into the project.
So how to get it working?
Today I observed a strange behavior in Maven 3 while preparing a release (with the Maven release plugin). As the description tends to be rather long, I would like to ask the question right before the description:
How do I achieve to use the release plugin
so that the build fork executes plugins in the right order
without having multiple executions of same plugins#
and get a valid plugin.xml for the Mojo
The artifact to be released is a Maven plugin itself (Mojo with Annotations). When invoking the release:prepare goal it first starts the process in interactive mode asking for the new version data of the release. After that it forks a new process doing a "clean verify" on the project that's supposed to be released.
As described by the console output the execution order of the invocation is
clean
plugin:descriptor (Maven-plugin-plugin)
resources
compile
testResources
testCompile
test
It seems as if plugin:descriptor is not able to find any Mojos as compilation has not been taken place:
[INFO] [INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) # concordion-maven-plugin ---
[INFO] [WARNING] Using platform encoding (Cp1252 actually) to read mojo metadata, i.e. build is platform dependent!
[INFO] [INFO] Applying mojo extractor for language: java-annotations
[INFO] [INFO] Mojo extractor for language: java-annotations found 0 mojo descriptors.
When configured in the right way, the plugin fails because of no mojo found.
If I configure the release plugin to explicitly invoke the compile goal using
<preparationGoals>clean compile verify</preparationGoals>
the order of plugin execution changes to the following:
clean
plugin:descriptor (Maven-plugin-plugin)
resources
compile
plugin:descriptor (this time finding the Mojo annotation)
resources
compile
testResources
testCompile
test
As the Mojo is found the plugin.xml is created with all the necessary data.
This is the whole build section of my pom.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<fork>false</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<goals>
<goal>
descriptor
</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4</version>
<configuration>
<dryRun>true</dryRun>
<preparationGoals>clean compile verify</preparationGoals>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>
This is my pom.xml build configuration:
<build>
<finalName>cfwd</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://xx.xxx.xxx.xxx:8080/manager/text</url>
<server>cifServer</server>
<path>/cfwd</path>
<addContextWarDependencies>true</addContextWarDependencies>
<addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
where http://xx.xxx.xxx.xxx:8080 is the remote server IP.
When I try to deploy via mvn tomcat:deploy I get this error:
[ERROR] Failed to execute goal
org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on
project cfwd: Cannot invoke Tomcat manager: Server returned HTTP
response code: 403 for URL:
http://localhost:8080/manager/deploy?path=%2Fcfwd&war= -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to
execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy
(default-cli) on project cfwd: Cannot invoke Tomcat manager
where it looks like maven is attempting to deploy to localhost:8080 rather than the remote server IP. Any idea?
You need to execute mvn tomcat7:deploy (note the '7') in order to trigger the plugin you've configured.
See this page for more information about the available goals.
403 means Forbidden.
Check with the official documentation in order to configure authentication to the Tomcat manager (parameters Server, password, username).
Duncan Jones is right : you are not executing the correct plugin : use tomcat7.