I am using a multi-module pom setup and when using the release plugin I am unable to do so.
I get the error:
Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5:prepare (default-cli) on project libraryparent: Can't release project due to non released dependencies :
com.xyz:libraryparent:pom:1.1-SNAPSHOT
in project 'utils' (com.xyz:utils:jar:1.1-SNAPSHOT)
the command I runs is:
mvn -B release:clean release:prepare release:perform -DdryRun=true -DdevelopmentVersion=1.2-SNAPSHOT -DreleaseVersion=1.1
Here is the major portions of the files that I think is relevant:
libraryparent
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>libraryparent</artifactId>
<version>1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent library</name>
<description>A parent pom for all library modules</description>
<modules>
<module>../util</module>
<module>../streams</module>
</modules>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
<configuration>
<releaseProfiles>release</releaseProfiles>
<goals>deploy assembly:single</goals>
<!--
<autoVersionSubmodules>true</autoVersionSubmodules>
-->
</configuration>
</plugin>
util
<project .....>
<modelVersion>4.0.0</modelVersion>
<artifactId>util</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.xyz</groupId>
<artifactId>libraryparent</artifactId>
<relativePath>../libraryparent/pom.xml</relativePath>
<version>1.1-SNAPSHOT</version>
</parent>
</project>
streams
<project .....>
<modelVersion>4.0.0</modelVersion>
<artifactId>streams</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.xyz</groupId>
<artifactId>libraryparent</artifactId>
<relativePath>../libraryparent/pom.xml</relativePath>
<version>1.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>util</artifactId>
<version>1.1-SNAPSHOT</version>
<!--
<version>${project.parent.version}</version>
-->
<classifier>j2me</classifier>
<optional>true</optional>
</dependency>
</dependencies>
</project>
I would suspect that the release plugin can set the versions to their release versions,etc.
Thanks.
The maven-release-plugin verifies if the parent and dependencies are part of the multimodule project. If it's not recognized it's either because of a different version or because of a typo in the groupId and/or artifactId. com.xyz is probably fake, so please check that value again.
Some may say that flat-projects (like this one) are not supported by the maven-release-plugin. However, there are a lot of integration-tests which do confirm that flat projects are supported.
I think I have just found the solution,
I will do a more complete test and post results shortly.
Change the maven-release-plugin goals from this:
<goals>deploy assembly:single</goals>
to this
<goals>deploy</goals>
...the end...
Related
I've just downloaded STS and started some maven project and it worked properly, but when I start using thymeleaf it doesn't work.
I see an exclamation mark on the project name, and I get this error Error: Could not find or load main class.
I tried adding its dependencies by myself in the POM, I get that error and it goes away once I remove them!
I also tried creating a "Spring Starter Project" and choosing dependencies "Web and Thymeleaf" to be added, right after the project is created I see a syntax error in the POM in the test dependency Failure to transfer org.springframework.boot:spring-boot-starter-test:jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
and when I remove it and its class, I get the same error above.
here is my POM now:
<?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.example</groupId>
<artifactId>demo-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo-2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.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.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Try to update your maven repository, try first:
mvn dependency:purge-local-repository
Description:
When run on a project, remove the project dependencies from the local
repository, and optionally re-resolve them. Outside of a project,
remove the manually given dependencies.
and then try:
mvn dependency:copy-dependencies
Description:
Goal that copies the project dependencies from the repository to a
defined location.
It seems to me that your local Maven repository doesn't include the thymeleaf dependecy.
The problem was solved after removing failed downloads:
from CMD:
cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i
then updating the project.
It re-downloaded the dependencies and it worked just fine.
Here is my requirement
EAR
WAR (Code)
----Dependency A v1
WAR (Code same as WAR above)
----Dependency A v2
AS the code for WAR project is same I don't want to create multiple code base for WAR project. So I'm looking for EAR pom.xml in such a way that maven builds the WAR with dependency A v1 which can be passed as some property while building WAR.
EAR pom.xml
...
(modules)
(webmodule)
(artifact)WAR(/artifact)
dependency version v1
(content-path)/warwithv1(/content-path)
(/webmodule)
(webmodule)
(artifact)WAR(/artifact)
dependency version v2
(content-path)/warwithv2(/content-path)
(/webmodule)
...
Thanks
Sorry for the XML Tags
EDIT: Answer changed after clarification in comments.
The question as I now understand it is: How does one use a single POM to create 2 WAR files that both have the same source code but different dependencies.
The solution I propose is to create a parent POM that will specify one module per WAR. One of the modules will contain the source code for the war and specify one version of dependencies. The second module will refer to the first module for its source code and will specify a second version of dependencies.
Here is my high level project structure:
Here is the top level (parent) 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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
</project>
Module1 will specify v2.3 of log4j2, here is its 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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>module1</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</project>
Module2 will specify v2.8.1 of log4j2 and point to module1 for its source code and web.xml file. Note that you may need to do additional work to refer to any other resources in module1 such as adding more maven plugins and configuration.
Here is the module2 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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>module2</artifactId>
<packaging>war</packaging>
<build>
<sourceDirectory>../module1/src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webXml>../module1/src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>
Note that I only have a single Java class in module1 just to show that in fact this class is compiled and included in both module1 and module2:
Here are the results of a simple clean install build:
Once you have the two WAR files built it's fairly simple to add another module (this would be your EAR) which will include both of the WAR files - I believe that is your final goal.
So, create a third module:
Add the new module to your root level (parent) POM:
<module>module3</module>
Create the necessary configuration in your new module's POM. This involves adding dependencies on the other two artifacts you create with module1 and module2 and configuring the ear plugin as needed.
<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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>module3</artifactId>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<applicationXml>${basedir}/target/application.xml</applicationXml>
<modules>
<webModule>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module1</artifactId>
</webModule>
<webModule>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module2</artifactId>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
Now when you build it will create an EAR that includes the 2 WARs generated by module1 and module2. The ear in this example is simply called module3:
EDIT: Original answer re-added per request in comments.
Here is the POM from the original proposal - using two profiles to specify different dependency versions. As before please note that it's not a good idea to include servlet api inside of a WAR file, it's just being used here as a visual example to show how common dependencies are specified.
<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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>v2.3</id>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>v2.8.1</id>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
I have a maven project with a parent pom and child modules, structured like this:
root/pom.xml
root/parent/pom.xml
root/child1/pom.xml
root/child2/pom.xml
root/child2/child21/pom.xml
Every child pom and the root pom declare root/parent as their parent. child21 has child1 as a dependency.
When I try to execute mvn install from the child1 directory, maven successfully builds and installs the child1 jar. But when i execute mvn install from either the child2 or child21 directories, maven errors out with the following:
[ERROR] Failed to execute goal on project child21: Could not resolve dependencies for project groupId:child21:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at groupId:child1:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for groupId:child1:jar:0.0.1-SNAPSHOT: Could not find artifact groupId:parent:pom:0.0.1-SNAPSHOT in jme-repo (http://updates.jmonkeyengine.org/maven/) -> [Help 1]
I have tried googling for what might be wrong with my project structure with no luck. Can anyone help suggest ways to get child21 to build?
My poms contain:
Root
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>
<artifactId>root</artifactId>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
Parent
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>child1</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
<dependencyManagement>
<repositories>
<repository>
<id>jme-repo</id>
<name>JME3 Official Maven Repo</name>
<url>http://updates.jmonkeyengine.org/maven/</url>
</repository>
</repositories>
<build>
<plugins>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
</configuration>
</plugins>
</build>
Child 1
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>child1</artifactId>
<packaging>jar</packaging>
<dependencies>...</dependencies>
Child 2
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>child2</artifactId>
<packaging>pom</packaging>
<modules>
<module>child21</module>
</modules>
Child 21
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
<artifactId>child21</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>child1</artifactId>
</dependency>
</dependencies>
UPDATE WITH SOLUTION
Based on the accepted answer below, I added the parent project as a module of the root pom:
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>
<artifactId>root</artifactId>
<packaging>pom</packaging>
<modules>
<module>parent</module>
<module>child1</module>
<module>child2</module>
</modules>
Then when developers build the project for the first time, the parent pom is installed. Subsequently they will be able to build the child2 and child21 projects independently.
This is a pretty awkward module structure, but it can still work. The problem is that when you are building module child21 (or child2), the child1 dependency is not a part of the current build, but is looked up in the repository. So is the parent of that dependency, which is the parent module. However, I assume, parent was never installed there - if you run mvn clean install on root, it does not build the parent, which is only referenced in the child modules by relative paths.
To fix it you must first install the parent POM into the repository. Run mvn install in the parent module. After that, build child1 - it will be installed into the repository as well. Now everything what is needed for building module child21 is available in the repository.
Change child21 to inherit from its parent - child2, see below:
<parent>
<groupId>groupId</groupId>
<artifactId>child2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
I am using the Maven release plugin and I am trying to make a release. When I am on master (I am using Git) I have SNAPSHOT versions for both my project (multimodule) and also for my dependencies (also multimodule).
Suppose I want to make a tag from master (skipping the creation of a branch) where no SNAPSHOTs are used.
This is my simplified 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>
<artifactId>results</artifactId>
<version>1.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Results parent module</name>
<modules>
<module>results-web</module>
<module>results-persistence</module>
<module>results-domain</module>
<module>results-logic</module>
<module>results-logic-api</module>
<module>results-ear</module>
<module>results-configuration</module>
<module>results-rules-ejb</module>
<module>results-rules</module>
<module>results-rest</module>
</modules>
<properties>
<dependency1.version>1.2.3-SNAPSHOT</main.version>
<dependency2.version>3.4.5-SNAPSHOT</main.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<tagNameFormat>#{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<localCheckout>true</localCheckout>
<pushChanges>false</pushChanges>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.my.project</groupId>
<artifactId>dependency1-domain</artifactId>
<version>${dependency1.version}</version>
</dependency>
<dependency>
<groupId>org.my.project</groupId>
<artifactId>dependency1-enumerations</artifactId>
<version>${dependency1.version}</version>
</dependency>
<dependency>
<groupId>org.my.project</groupId>
<artifactId>dependency1-logic</artifactId>
<version>${dependency1.version}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>org.my.project</groupId>
<artifactId>dependency2-domain</artifactId>
<version>${dependency2.version}</version>
</dependency>
<dependency>
<groupId>org.my.project</groupId>
<artifactId>dependency2-enumerations</artifactId>
<version>${dependency2.version}</version>
</dependency>
<dependency>
<groupId>org.my.project</groupId>
<artifactId>dependency2-logic</artifactId>
<version>${dependency2.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
</dependencyManagement>
If I do:
mvn release:prepare -Darguments="-dependency1.version=1.2.3.0
-Ddependency2.version=3.4.5.0"
That creates a branch that still has SNAPSHOT dependencies:
<properties>
<dependency1.version>1.2.3-SNAPSHOT</main.version>
<dependency2.version>3.4.5-SNAPSHOT</main.version>
</properties>
How would I generate a tag where the part above would be:
<properties>
<dependency1.version>1.2.3.0</main.version>
<dependency2.version>3.4.5.0</main.version>
</properties>
The release plugin cannot change dependency versions in the POM that are not part of the reactor.
Try the Maven Versions Plugin. You can use versions:use-releases to replace all snapshot dependencies with the corresponding releases. If you would like to replace them manually (perhaps because the versions differ from the snapshots) you can use versions:set. But both do not work with dependency versions supplied in properties. For properties versions:update-properties is used with the setting allowSnapshots=false. This goal works automatically if no special version ranges are required but it is configurable to deal with such requirements, too.
You can configure the release plugin to call your versions plugin using preparaionGoals as Stephen stated: <preparationGoals>clean versions:use-releases verify</preparationGoals>
Or you call the versions plugin manually before the release, e.g. with
mvn versions:use-releases scm:checkin -Dmessage="Release versions of dependencies"
The release plugin is not designed to address this use case.
You might be able to get somewhere by hijacking preparationGoals and completionGoals to call plugins that edit your pom... Certainly that was the use case I had in mind when I added completionGoals
But for now, in the absence of being able to get a plugin to edit and unedit your pom to set the versions you will have to live with editing by hand
I have two maven modules, A and AB, with AB depending on test files in A. Both reference a parent pom.
I discovered the magic of test-jar which allowed me to compile my program, but I still cannot run tests with mvn test.
Strangely enough, mvn package tests seems to work.
Here's my basic configuration:
...
<parent>
<groupId>com.acme.parent</groupId>
<artifactId>parent</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.0</version>
</parent>
<groupId>com.acme</groupId>
<artifactId>A</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Project AB (depends on A)
...
<parent>
<groupId>com.acme.parent</groupId>
<artifactId>parent</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.0</version>
</parent>
<artifactId>AB</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependency>
<groupId>com.acme</groupId>
<artifactId>A</artifact>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.acme</groupId>
<artifactId>A</artifact>
<version>1.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
...
And finally, the relevant bits from the parent pom:
...
<groupId>com.acme.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>A</module>
<module>AB</module>
</module>
...
So, with all that said, how do I make mvn tests run as expected?
I'm using maven 2.2.1 by the way.
This may be related to one of the unresolved bugs like MNG-3559.
Essentially, the test classes of Project A are not visible to Project AB if only mvn test is run from parent pom. They are visible once the jar for package A is created (during the package phase).