Should the EAR pom inherit a parent - maven

This is as much a question about the use of maven <dependencymanagement> section as much as it is about how and EAR module should play out.
I have a typical use case. Following are the maven modules
parent
api
ejb
web
ear
ear has api, ejb and web listed as its dependencies and inherits from parent like the other modules.
Here is the dependency management section for parent.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.4</version>
</dependency>
</dependencyManagement>
and for ejb I have a dependency (not under dependency management section but a dependency) with an explicit override of the version.
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5</version>
</dependency>
When I build the whole project from the parent (since they are aggregated in the parent pom), the EAR project creates the end EAR artificat.
So far so good, but the problem arises in the way the dependencies resolve. My instinct would be that because the ejb module lists spring core version 2.5 explicitly, that would get packaged as the dependency. But what actually happens is that the EAR module being a child of the parent pom uses the version mentioned in the dependency management section of the parent and ends up taking 3.4 as the spring core version.
After a lot of study I was convinced that this is as per the Maven documentation. But what I now think about is if I combine the strategy of having the parent pom controlling all dependency versions with the strategy of the EAR module inheriting the parent, I am essentially 'stuck' with (in some cases) what the parent defines with no chance to override it.
Although one could argue that one should ideally have the same version of the jar throughout, there are some situations you run into where you would like to override some dependency versions.
What is the correct approach to let me be able to override a version? The use of spring in this example is just for example purposes. It could be any other jar.

Dependency Management actually allow you to centralize the management of dependency versions without having to add dependencies within all children (talking about common dependencies). This brings much help when having multi-inheritance level project where children get the could get the transitive dependencies from the parent pom just like your project.
Concerning version override, don't be mistaken because you can override the inherited dependency version just by declaring it in the sub-module who needs to have its own version of some artifact.
Here is a sample showcase of that, stating a straightforward project with name root and having two sub-modules; blessed-module the one that inherite his parent artifact version and an odd-module which has chosen his own path and so his own artifact version:
root
\+ blessed-module
+ odd-module
The parent pom will state the centralized dependencies having below descriptor (pom.xml):
<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>dependency.management.showcase</groupId>
<artifactId>root</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>blessed-module</module>
<module>odd-module</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
The child modules will be as follows, starting with the good blessed-module:
<?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>
<parent>
<groupId>dependency.management.showcase</groupId>
<artifactId>root</artifactId>
<version>1.0</version>
</parent>
<artifactId>child-module</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
</project>
and the pom.xml file of the odd-module:
<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>
<parent>
<artifactId>root</artifactId>
<groupId>dependency.management.showcase</groupId>
<version>1.0</version>
</parent>
<artifactId>odd-module</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>
Now no further actions are needed, jsut go navigate to the root home path and execute below maven command from a terminal to have all dependencies tree shown in front of you
mvn dependency:tree
You will see the sub-modules with slightly different versions of the spring-core artifact:
[INFO] ------------------------------------------------------------------------
[INFO] Building root 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # root ---
[INFO] dependency.management.showcase:root:pom:1.0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building child-module 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # child-module ---
[INFO] dependency.management.showcase:blessed-module:jar:1.0
[INFO] \- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
[INFO] \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building odd-module 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # odd-module ---
[INFO] dependency.management.showcase:odd-module:jar:1.0
[INFO] \- org.springframework:spring-core:jar:2.5:compile
[INFO] \- commons-logging:commons-logging:jar:1.1:compile
[INFO] ------------------------------------------------------------------------

Related

How to supress maven-javadoc-plugin run form parent pom.xml?

I have a pom.xml https://repo1.maven.org/maven2/com/miglayout/miglayout-swing/5.2/miglayout-swing-5.2.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>
<parent>
<groupId>com.miglayout</groupId>
<artifactId>miglayout-parent</artifactId>
<version>5.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>miglayout-swing</artifactId>
<packaging>jar</packaging>
<name>MiGLayout Swing</name>
<description>MiGLayout - Java Layout Manager for Swing</description>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>miglayout-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
with this sources https://repo1.maven.org/maven2/com/miglayout/miglayout-swing/5.2/
And I got the following error:
INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.475 s
[INFO] Finished at: 2021-07-13T14:12:16+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.0:jar (attach-javadocs) on project miglayout-swing: MavenReportException: Error while generating Javadoc:
[ERROR] Exit code: 1 - Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
[ERROR] javadoc: error - The code being documented uses modules but the packages defined in https://docs.oracle.com/javase/8/docs/api/ are in the unnamed module.
Please tell me how to completely TURN OFF maven-javadoc-plugin? I need to build this project without javadoc.
Thank you
You can set the property maven.javadoc.skip to true, i.e. in your <properties> section add something like
<maven.javadoc.skip>true</maven.javadoc.skip>

spring and mongodb integration issue -correct the classpath of your application so that it contains a single, compatible version

I am working on spring, flowable and mongodb.
here is my pow
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-engine</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-process-engine-mongodb</artifactId>
<version>6.4.0.alpha1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
when running, it throws out an error
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.mongodb.MongoClientOptions.<init>(MongoClientOptions.java:149)
The following method did not exist:
'com.mongodb.connection.ConnectionPoolSettings$Builder com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(int)'
The method's class, com.mongodb.connection.ConnectionPoolSettings$Builder, is available from the following locations:
jar:file:/Users/abc/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar!/com/mongodb/connection/ConnectionPoolSettings$Builder.class
The class hierarchy was loaded from the following locations:
com.mongodb.connection.ConnectionPoolSettings.Builder: file:/Users/abc/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.mongodb.connection.ConnectionPoolSettings$Builder
firstly, i don't know where maxWaitQueueSize function is being used, because this function exists in mongodb driver 3.6.0-beta1 not in 4.x.x version,
I tried add the pom
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.6.0-beta1</version>
</dependency>
then running the pom with new errors saying
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.mongodb.MongoClientOptions.<init>(MongoClientOptions.java:149)
The following method did not exist:
'com.mongodb.connection.ConnectionPoolSettings$Builder com.mongodb.connection.ConnectionPoolSettings$Builder.maxWaitQueueSize(int)'
The method's class, com.mongodb.connection.ConnectionPoolSettings$Builder, is available from the following locations:
jar:file:/Users/abc/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar!/com/mongodb/connection/ConnectionPoolSettings$Builder.class
jar:file:/Users/abc/.m2/repository/org/mongodb/mongo-java-driver/3.6.0-beta1/mongo-java-driver-3.6.0-beta1.jar!/com/mongodb/connection/ConnectionPoolSettings$Builder.class
The class hierarchy was loaded from the following locations:
com.mongodb.connection.ConnectionPoolSettings.Builder: file:/Users/xisizhe/.m2/repository/org/mongodb/mongodb-driver-core/4.1.2/mongodb-driver-core-4.1.2.jar
I tried to delete the mongodb-driver-core-4.1.2.jar, but when running again the mongodb-driver-core-4.1.2.jar will be downloading automatically again, and the project will keep using the 4.1.2 version instead of mongo-java-driver-3.6.0 configured in the pom.xml
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.3.3.RELEASE:run (default-cli) > test-compile # demo >>>
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.pom (1.8 kB at 1.0 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.pom (1.3 kB at 2.7 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.pom (3.1 kB at 7.6 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver/3.8.2/mongodb-driver-3.8.2.jar (320 kB at 339 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/bson/4.0.5/bson-4.0.5.jar (492 kB at 178 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/mongodb/mongodb-driver-core/4.0.5/mongodb-driver-core-4.0.5.jar (1.6 MB at 550 kB/s)
The thing puzzled me most is I don't configured any mongodb-driver-core-4.1.2 in the pom.xml, where it is coming from ?
is there a way to solve this?
I wasn't quite able to reproduce your issue with your pom, I got the following:
Factory method 'mongo' threw exception; nested exception is java.lang.NoClassDefFoundError: com/mongodb/connection/DefaultClusterFactory
Regardless, the issue is most likely that MongoAutoConfiguration, which kicks in when there is an available MongoClient in the classpath is incompatible with the mongodb-driver version that the flowable-process-engine-mongodb lib depends on. If you run mvn dependency:tree you will see the following:
[INFO] \- org.flowable:flowable-process-engine-mongodb:jar:6.4.0.alpha1:compile
[INFO] +- org.mongodb:mongodb-driver:jar:3.8.2:compile
[INFO] | +- org.mongodb:bson:jar:4.1.2:compile
[INFO] | \- org.mongodb:mongodb-driver-core:jar:4.1.2:compile
Simply excluding this jar from this dependency allows me to run the app, like so:
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-process-engine-mongodb</artifactId>
<version>6.4.0.alpha1</version>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
But you probably want to configure a MongoClient in your application, in which case you will need to replace the excluded jar:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
Which is a synchronous driver for mongoDB but you can use the async driver as well. You don't have to provide a version as it's a managed dependency.
Alternatively, you could exclude the MongoAutoConfiguration in your main application class:
#SpringBootApplication(exclude = MongoAutoConfiguration.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Which would allow you to keep the original dependency but you won't have any of the Beans available that would otherwise be configured in the MongoAutoConfiguration configuration class.

Maven: Why am I getting servlet-api-2.5

I'm creating a web application with Maven, and I'm having a problem - for some reason I get servlet-api-2.5.jar included, which gives weird exceptions. Removing this file from the WAR archive solves all problems, but I'm trying to understand why it's there in the first place. My dependencies in the complete pom.xml file is:
<?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.sillyfly.webapp</groupId>
<artifactId>Webapp</artifactId>
<version>0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webXml>web/WEB-INF/web.xml</webXml>
<webappDirectory>web</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-impl</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-jstlel</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-spec</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
And running mvn dependency:tree -Dverbose yields:
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - org.sillyfly.webapp:Webapp:jar:0.1
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] org.sillyfly.webapp:Webapp:jar:0.1
[INFO] +- org.glassfish:javax.json:jar:1.0.4:compile
[INFO] +- org.apache.taglibs:taglibs-standard-impl:jar:1.2.5:compile
[INFO] +- org.apache.taglibs:taglibs-standard-jstlel:jar:1.2.5:compile
[INFO] +- org.apache.taglibs:taglibs-standard-spec:jar:1.2.5:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.38:compile
[INFO] \- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Sat Mar 26 12:12:32 IDT 2016
[INFO] Final Memory: 24M/515M
[INFO] ------------------------------------------------------------------------
Where there is no mention for servlet-api-2.5.jar.
I'm now noticing it says jar and not war, so I guess my question is twofold:
1. Are the JAR and WAR dependencies different, and if so how do I get Maven dependency plugin to show me the WAR dependencies?
2. How can I explicitly tell Maven not to include servlet-api-2.5.jar? I've tried adding an exclusion in various places, but since I don't know why it's there in the first place it's mostly a guessing game as to where to put the exclusion, and none of the places I've tried have worked.
mvn --version for referene:
Apache Maven 2.2.1 (rdebian-23)
Java version: 1.8.0_72-internal
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "4.4.0-1-amd64" arch: "amd64" Family: "unix"
Edit: I updated to Maven 3.3.9 and I still get the exact same result. The only difference is that the dependency tree shows dependencies between the various apache taglibs libraries, but still no mention of servlet-api-2.5.
I can't reproduce your problem from the information you gave, so the root cause must be somewhere else.
Do you see the extra servlet JAR when running mvn package from the command line, or could it be a strange effect of your IDE?
If the problem persists, try to reduce your app to a minimum and create a self-contained project e.g. on GitHub that people can look at.
By the way, you must never include the servlet API in WEB-INF/lib (not twice, and not even once). Always use Maven scope provided for the servlet API.
Normally there is a dependency in your project that is depending on servlet-apî.jar.
The default behaviour of Maven is that i wiill try to import your dependency + the dependencies of the imported dependency.
If you want to exclude a specific "sub-dependency", you can give maven a configuration like this :
<dependency>
<groupId>com.hpsworldwide.mbtrs.switch</groupId>
<artifactId>DEPENDENCY</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
The culprit was lib/ and classes/ folders in the source's WEB-INF, which contained the jars that got included. The folders were created due to faulty pom configuration (see below). Situation was visible after enabling Maven debug output (mvn -X) when running Maven.
Removing these folders solved all of my problems.
Edit: After getting the same folders again, I found out the root of the cause - I have used <webappDirectory>, when I should have used <warSourceDirectory>.

Maven versions-maven-plugin versions plugin 2.2 -- Maven Uncle Situation

Maven is 3.1.0.
I'm using versions-maven-plugin:2.2 in my project's pom.xml (as shown below). Apart from the usual pom.xml file configuration, I'm just showing the main code snapshot below:
<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>
<artifactId>tools-parent</artifactId>
<version>0.0.7-SNAPSHOT</version>
<packaging>pom</packaging>
<description>
Infrastructure related to the "vapp" and
"deployer" utilities.
</description>
<parent>
<groupId>com.company.product</groupId>
<artifactId>deploy-parent</artifactId>
<version>0.0.6-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
<configuration>
<connectionType>connection</connectionType>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<!-- Make sure that only non-snapshot versions are used for the dependencies. Only active when property 'snapshotDependencyAllowed' is false. -->
<id>enforce-no-snapshots</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<skip>${snapshotDependencyAllowed}</skip>
<rules>
<requireReleaseDeps>
<message>No Snapshots Allowed!</message>
</requireReleaseDeps>
<requireReleaseVersion>
<message>No Snapshots Allowed!</message>
</requireReleaseVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Now, when I run: mvn clean install, it builds successfully.
NOTE: In my project, I have a parent section, where I'm dependent upon deploy-parent artifact whose group id "com.company.product" is the same group id what I want to tools-parent artifact (whose pom.xml I have pasted above) but deploy-parent is an artifact of another repository/project.
When I run: mvn versions:set -DnewVersion=0.0.7, I get the following error message.
[INFO] ------------------------------------------------------------------------
[INFO] Building tools-parent 0.0.7-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:set (default-cli) # tools-parent ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /user/home/u100123/giga/tools
[INFO] Processing change of com.company.product:tools-parent:0.0.7-SNAPSHOT -> 0.0.7
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] tools-parent .................................... FAILURE [1.093s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.404s
[INFO] Finished at: Fri May 01 20:44:22 GMT-00:00 2015
[INFO] Final Memory: 12M/246M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.2:set (default-cli) on project tools-parent: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.2:set failed. NullPointerException -> [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/PluginExecutionException
NOW, when I change the versions-maven-plugin version back to 2.1 (which what I was using earlier), the above mvn versions:set -DnewVersion=0.0.7 command is working successfully and pom.xml file is successfully getting changed to <version>0.0.7</version> for tools-parent artifact.
With version 2.2, it's giving me the error and not changing the version to 0.0.7.
Any reasons why 2.2 is failing? What can be done to resolve it?
It seems like some bug.
Solution:
1. I have to add <groupId>com.company.product</groupId> property outside of ... section as well i.e. for tools-parent, NOW version-maven-plugin:2.2 is working fine i.e. I added the top line (as shown below). The only thing is, what's the use of parent section then (apart from inheriting the main code of what deploy-parent is brining to tools-parent project). Why groupId needs to be defined output of parent section for artifactId tools-parent when it's already there in the parent section for versions-maven-plugin:2.2 to work successfully.
The most important thing is: This issue occurs only in case your pom.xml for a project/module has a <parent> section where the parent section's artifactId is not the parent of the project itself (a typical - Maven Uncle situation) i.e. if tools-parent artifact is defined in the parent section of another module (lets say tools-child) then version 2.2 will work successfully. But if tools-child's parent section is not containing the artifactId as "tools-parent" and is something else for ex: deploy-parent/some-different-project-artifact (which resides in a different project in your source control tool) then, for tools-child artifactId, we need groupId value also set outside of the parent section as well (even if the groupId of parent section's artifactId is same/different to tools-child's groupId).
<groupId>com.company.product</groupId>
<artifactId>tools-parent</artifactId>
<version>0.0.7-SNAPSHOT</version>
<packaging>pom</packaging>
<description>
Infrastructure related to the "vapp" and
"deployer" utilities.
</description>
<parent>
<groupId>com.company.product</groupId>
<artifactId>deploy-parent</artifactId>
<version>0.0.6-SNAPSHOT</version>
</parent>
--OR
2. Switch back to versions-maven-plugin:2.1
Just to add to part 2 of Arun's answer, the way to use version 2.1 of the plugin is:
mvn org.codehaus.mojo:versions-maven-plugin:2.1:set org.codehaus.mojo:versions-maven-plugin:2.1:commit -DnewVersion=0.0.7
You have to specify the full group-id and artifact-id.
Found this bug reported on the issue:
https://github.com/mojohaus/versions-maven-plugin/issues/51
I ran into a NPE too but it turns out the reason was a different one than suggested earlier. I debugged the versions-maven-plugin and found out that the NPE was caused by a missing <version> declaration of a dependency in the listed in the <dependencyManagement>. This can be reproduced with the following listing:
<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.example</groupId>
<artifactId>npe</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>NPE Example</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<!-- missing <version>4.2.0.RELEASE</version> -->
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
</dependencies>
</project>

How to build a multi-module maven project in jenkins

I have a projects structure as follows:
ProjectParent
- pom.xml
ProjectApp
-pom.xml
ProjectAPI
-pom.xml
ProjectModels
-pom.xml
ProjectServices
-pom.xml
Etc..
ProjectModels/ProjectsServices are dependencies within ProjectAPI/ProjectApp.
Should I create separate jobs within Jenkins to build each module separately?
I created a job for ProjectAPP but get the following error below (Have set goals and actions to "clean install":
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject-app 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT is missing,
no dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-entities/0.0.1-SNAPSHOT/myproject-entities-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT is missing, no
dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-services/0.0.1-SNAPSHOT/myproject-services-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-services:jar:0.0.1-SNAPSHOT is missing, no
dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-persistence/0.0.1-SNAPSHOT/myproject-persistence-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT is missing, no
dependency information available
Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.jar
......
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project myproject-app: Could not resolve dependencies
for project com.myproject:myproject-app:war:0.0.1-SNAPSHOT: The
following artifacts could not be resolved:
com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT,
com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT,
com.myproject:myproject-services:jar:0.0.1-SNAPSHOT,
com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT: Could not find
artifact com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT in
org.springframework.maven.snapshot
(http://maven.springframework.org/snapshot)
ProjectParent Pom
<?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.myproject</groupId>
<artifactId>myproject-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>myproject-entities</module>
<module>myproject-services</module>
<module>myproject-persistence</module>
<module>myproject-app</module>
<module>myproject-merchant</module>
<module>myproject-common-config</module>
<module>myproject-api</module>
</modules>
<dependencyManagement>
<dependencies>
...
</dependencies>
</dependencyManagement>
<repositories>
...
</repositories>
<build>
...
</build>
<properties>
...
<myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
<myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
<myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
</properties>
</project>
ProjectApp Pom
<?xml version="1.0"?>
<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>
<parent>
<groupId>com.myproject</groupId>
<artifactId>myproject-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>myproject-app</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>myproject-app</name>
<url>http://maven.apache.org</url>
<dependencies>
...
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-common-config</artifactId>
<version>${myproject-common-config}</version>
</dependency>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-entities</artifactId>
<version>${myproject-entities-version}</version>
</dependency>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-services</artifactId>
<version>${myproject-services-version}</version>
</dependency>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject-persistence</artifactId>
<version>${myproject-persistence-version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<myproject-common-config>0.0.1-SNAPSHOT</myproject-common-config>
<myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
<myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
<myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
</properties>
</project>
Am I using the wrong goals? Do I need to chain a number of commands? i.e. build other modules first?
I'm using Maven 3.
NOTE: I changed the target to "clean install" against the ParentProject Pom and everything builds correctly.
Thanks
The problem is that you can't create a project solely for the ProjectApp module because it depends on the other modules below the ProjectApp parent. If you don't deploy those modules to your maven repository, maven is not able to find them in the repository nor in the build reactor.
Instead you should create the job for the parent. This will build the necessary modules.
You may also work with the option also-make-dependants when you have a job for ProjectApp, but I haven't any experience with this.
Had the same problem, and SpaceTrucker answer helped me.
Hence I just run something like:
.../ProjectParent$ mvn -am -pl ProjectApp test

Resources