Cannot create jar files for Maven project - maven

I Have very complex Maven project with multiple Feature file , for below POM.XML , I cannot create jar file
MAven Install Package is failing as below:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:testCompile
If I change jre version to 1.7 , am getting error for dimond symbol <>
Could someone help to build Jar file ?
POM.XML :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<fork>true</fork>
<executable>C:\Program Files\Java\jre1.8.0_161\bin\javac</executable>
</configuration>
</plugin>

I think your maven compiler section is using an out of date plug in. You're using 3.3, the latest is version 3.7.0 so I'd update to that.
For example my pom.xml contains:
<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>
I'm also running the latest version of Maven on my development box too, which I think is 3.5.3 but I could be very much mistaken on that front.
Maven Central is a great place to look stuff like this up. The link for the compiler plugins is provided below:
https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin
Hope that helps.

Related

when to use <build> plugin in maven pom.xml?

In our project, we have configured jetty inside build plugin in pom, i want to understand configuration settings in pom/ what and all we can configure in pom.
what is <build><plugin> section in pom, when to use.
difficult to understand from tutorials because lot of different examples which is making confuse.
Please can somebody explain for the above in detail?
Plugins defined in your buildsection plugins tag will be executed during the build of your project.
There are many plugins that do something with your build.
For example the maven-compiler-plugin which allows you to set the Java version for your project.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
a list of maven build plugins supported by maven itself

Installing and compiling Maven artifacts on Java 8

I have a project with a pom.xml that has the following <build> declaration:
<build>
<plugins>
<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>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
When I run mvn install on this project, it compiles the project, runs unit tests and publishes it to my local repo. I am trying to learn a little more about Maven here, and am having a tough time finding documentation/explanations on the following:
How am I able to run mvn install, if the POM doesn't declare it under build/plugins? Does maven-compiler-plugin include maven-install-plugin, if so, how could I have figured that out?
Most importantly: the value of build/plugins/plugin/configuration/source and .../target are both set to 1.8. If my machine has Java 8 on it, and I run mvn install on this project without any errors, does that guarantee that the project builds with Java 8? I'm looking at the docs for the Compiler Plugin and don't see those source/target configs listed anywhere.
First you should learn what the build life cycle is and how it works and how the plugins are bound to the life cycle by default.
Furthermore you should understand that in Maven every project inherits from the super pom file which is part of the maven distribution (the package you have downloaded). The super pom defines the default folder layout and some versions of plugins.
The question to define the maven-compiler-plugin as you did is to be very accurate simply wrong. You should have defined it like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This would overwrite the definition which is inherited by the super pom and changes it's configuration. In your case i would suggest to change the definition into this:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<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>
</plugins>
</pluginManagement>
</build>
..
</project>
The encoding should be set globally cause there are other plugins which use this definition like the maven-resources-plugin. The usage of the above property simplifies this, cause every plugin which has an option for encoding will use the default as defined in the property.
To be sure using the correct version of Java (your JDK on your machine) you have to use the maven-enforcer-plugin.
Apart from that please take a look onto the plugins page which shows the most up-to-date releases of the plugins.
As a good documentation i can recomment the Books on Maven but be aware they are written with Maven 2 in mind. So if something is not clear ask on users mailing list of here on SO.

Maven release:prepare : Cannot prepare the release because you have local modifications

I'm facing a problem with continuum's release:prepare phase which fails in scm-check-modifications step with error :
[ERROR] org.apache.maven.shared.release.ReleaseFailureException:
Cannot prepare the release because you have local modifications :
[pom.xml:modified]
What i did :
I commited all my changes (*.java and pom.xml) into SVN
I made a build of the project in Continuum
I launched the preparation of the release.
I know that the scm-check-modifications calls ScmCheckModificationsPhase class that verifies that there are no local changes compared to what is on the SCM.
I understand if i'm working with only Maven, if there are some locally changes, or any differences between the local code and the SVN for example, release:prepare won't work, because it checks for modifications first; but working with Continuum,i don't know why it should be a differencse between the local code and the SVN repository ? So i don't know why the release:prepare goal in Continuum is facing that problem.
Example of my pom :
<build>
<plugins>
...
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
</configuration>
</plugin>
...
</plugins>
</build>
<scm>
<connection>scm:cvs:ext:url:/var/cvs:application_name</connection> <developerConnection>scm:cvs:ext:url:/var/cvs:application_name</developerConnection>
</scm>
.....
</project>
In the parent pom.xml:
...
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<goals>deploy</goals>
<arguments>-Prelease</arguments>
</configuration>
</plugin>
.....
For information, the build and the release of the project is always working fine, until now.
There is a Bypass solution that solved my issue but i still seeking to understand the origin of this problem.
The bypass solution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<configuration>
...
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
I can confirm, that adding the plugin or configuring it to exclude the pom.xml check did work:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
Removing my project's target folder from source control fixed this issue for me.
For everybody who don't want to change the pom.xml a commandline option does the trick:
mvn [...] -DcheckModificationExcludeList=pom.xml,.maven/spy.log
I had the problem on our hudson / jenkins CI environment which complained about changes in the .maven/spy.log
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
<checkModificationExclude>**</checkModificationExclude>
</checkModificationExcludes>
</configuration>
For me solution is staging and commiting pom.xml or any other changed file to push git
This is just a workaround for the error . i faced same error with maven-release plugin version 2.5.3 and just sorted the error with maven-release 2.3.2

version mismatch of maven-compiler-plugin

I have this lines under our pom.xml file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<jdkLevel>1.6</jdkLevel>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I am using apache-maven-2.2.1 version .
Will it be any problem as the versions of maven-compiler-plugin and maven Version does not match ??
Please suggest , thank you very much .
The versions of maven and its plugins never match. There is no coordination of the releases. It is very rare for there to be compatibility issues and when they exist they are documented on the plugin documentation pages.

Maven Install: "Annotations are not supported in -source 1.3"

When running mvn install on my project, i see it fail due to the following errors:
C:\Repositories\blah\src\test\java\com\xxx\qm\testrunner\test\ATest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
C:\Repositories\blah\src\test\java\com\xxx\qm\common\test\BTest.java:[11,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
My Maven dependency includes jUnit 4.8, however and has no reference to 1.3 anything.
What would cause these errors? Please advise
You need to specify the source version of your maven project through the use of the maven-compiler-plugin. Add the following to your pom build element and set the appropriate java source and target levels.
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/plugins/maven-compiler-plugin/
A shorter version:
<project>
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>
....
You are most likely using OpenJDK where the source level is 1.3 when not explicitly set - as opposed to Oracle JDK where the source level is 1.5.
Since most modern Java projects target newer code than Java 5 you most likely need to set this anyway.
Also note that if you need a lower target than source (e.g. for compiling with Java 6 but deploying to Java 5) you can do this by using the Eclipse compiler instead of Javac.
Bu default, the maven tries to compile using Java 1.3 version. I hope most of them hit this error because of missing to tell maven that "Hey Maven, Dont use 1.3 and use "whatever_version_I_give"
This can be mentioned in pom.xml as below :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
In my above example, I have used 1.7. Please replace with whatever version you wish to.
Add this in your pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Resources