I have a Maven project and now want to release it with the maven-release-plugin. Unfortunately after executing mvn release:prepare the git tag contains the old version number (1.0-SNAPSHOT) and when deploying to artifactory the SNAPSHOT version is used instead of the desired release version.
I already found this bug, but all suggested solutions are not working for me.
I'm using:
Apache Maven 3.3.9
git version 2.7.0 (German)
I already tried several versions of the release plugin (2.4, 2.5.3, 2.5.1) but none woked.
Does anyone have a fix for that problem?
EDIT1: The current pom.xml
<?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>mygroupid</groupId>
<artifactId>myartifact</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- [...] -->
<scm>
<url>http://url/to/gitlab</url>
<connection>scm:git:git#gitlab:group/repo.git</connection>
<developerConnection>scm:git:git#gitlab:group/repo.git</developerConnection>
<tag>HEAD</tag>
</scm>
<!-- [...] -->
<distributionManagement>
<!-- [...] -->
</distributionManagement>
</project>
Related
I have 2 maven projects where one depends on another. Let's call them common and service.
service specifically depends on a module within common we'll call common-module.
If I make an update to common-module and run mvn clean install, it gets properly installed to my local repository.
Problem
In service, when I do a mvn clean package/install or mvn -U clean package/install will pick up the version that's in the remote repository even though the one I just built is newer. I cannot get it to pick up that latest version even though I see it in my .m2/repository.
How can I get it to pick my locally built jar?
Setup
pom.xml for common (simplified, a lot is excluded)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>common-parent</artifactId>
<version>2.4.5-SNAPSHOT</version>
<name>Common Parent</name>
<modules>
<module>common-module</module>
</modules>
</project>
pom.xml for common-module (simplified, a lot is excluded)
<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">
<artifactId>common-module</artifactId>
<name>common-module</name>
<description>common-module</description>
<parent>
<artifactId>common-parent</artifactId>
<groupId>com.company.group</groupId>
<version>2.4.5-SNAPSHOT</version>
</parent>
</project>
pom.xml for service (simplified, a lot is excluded)
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>service</artifactId>
<name>service</name>
<version>1.2.3-SNAPSHOT</version>
<dependencies>
<dependency>
<artifactId>common-module</artifactId>
<groupId>com.company.group</groupId>
<version>2.4.5-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Note 1: I have a workaround where I can adjust the library settings within IntelliJ and force it to use the correct jar file, but this feels very hacky and unsustainable to me.
Note 2: I've tried changing the <updatePolicy> value in my settings.xml to never and other values, but it seems to have had no effect. This was suggested in other posts I've read before asking here.
<repository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>http://internal.url/repository/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
Recently we tried to deploy files using jenkins providing ${revision} property for the build ( Maven 3.3.9 ).
It worked OK on json creating 0.0.1-SNAPSHOT for dev builds and 0.0.1-RC for releases, but we have an issue using maven on developer machines.
We have multi-module maven project with version defined in parent and some modules uses others as dependencies. Both build it from jenkins and use maven locally, to integrate with IDEs and run tests before pushing it into repository.
When we try to build a single module, maven does not recognize ${revision}, although it works fine when we mention all modules e.g. mvn clean install -pl appserver, we see
Failed to execute goal on project appserver: Could not resolve dependencies for project com.org:appserver:war:0.0.1-local: Failed to collect dependencies at com.org:my-kinesis-events:jar:0.0.1-local: Failed to read artifact descriptor for com.org:my-kinesis-events:jar:0.0.1-local: Could not transfer artifact com.org:my-parent:pom:${revision} from/to central: Failed to transfer .../repository/maven-central/com/org/my-parent/${revision}/my-parent-${revision}.pom. Error code 500, Server Error -> [Help 1]
We tried to use:
-Drevision=0.0.1-local
<profile>
<id>default-version</id>
<activation>
<property>
<name>!revision</name>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<revision>0.0.1-local</revision>
<project.version>0.0.1-local</project.version>
</properties>
</profile>
but the only thing that works is a build for parent that that builds the module and all modules it depends on:
mvn clean install -pl appserver,my-kinesis-events,module1,module2,...
Although the above works it requires from the team to define custom run configuration in IDE, each time they need something.
Did somebody also experienced this issue and found the solution?
Parent pom snippet:
<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.org</groupId>
<artifactId>my-parent</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>My Parent module</name>
<modules>
<module>../my-tools</module>
<module>my-kinesis-events</module>
....
</modules>
.....
</project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>my.org</groupId>
<artifactId>my-kinesis-events<</artifactId>
<version>${project.version}</version>
<dependency>
<dependencies>
</dependencyManagement>
Module pom snippet:
<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>appServer</artifactId>
<parent>
<groupId>com.org</groupId>
<artifactId>my-dsp</artifactId>
<version>${revision}</version>
<relativePath>..</relativePath>
</parent>
<packaging>war</packaging>
<name>AppServerAPI</name>
<description>Application Server</description>
<dependencies>
<dependency>
<groupId>com.org</groupId>
<artifactId>my-openrtb</artifactId>
</dependency>
.....
</dependencies>
....
</project>
These issues have been fixed since Maven 3.5, you need however to use the maven flatten plugin to ensure that all variables are removed from your POM before publishing. Otherwise you end up having POM containing ${revision} has version.
This is neatly explained in the official maven documentation:
https://maven.apache.org/maven-ci-friendly.html#install-deploy
I have a maven project that contains two submodules, one depends on there other.
The project has no code but maven is ok with that. If I perform mvn package it passes ok and generates (empty) jar files.
However if I do mvn dependency:list I get the following error:
Failed to execute goal on project foob-two: Could not resolve dependencies for project com.example.foob:foob-two:jar:1.0.0-SNAPSHOT: Failure to find com.example.foob:foob-one:jar:1.0.0-SNAPSHOT in [Repo]
It seems like the maven dependency plugin only works after the modules have been uploaded to the local repo.
Strangely if I do the dependency list at the same time as package, ie mvn package dependency:list, it works. So it seems that maven has a different dependency resolution mechanism in some contexts.
Can anyone explain the behaviour? Can I run mvn dependency:list as a standalone command?
Here's the root 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.example.foob</groupId>
<artifactId>foob</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>foob-one</module>
<module>foob-two</module>
</modules>
</project>
Here's the first subproject:
<?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">
<parent>
<groupId>com.example.foob</groupId>
<artifactId>foob</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>foob-one</artifactId>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
</project>
Here's the second project:
<?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">
<parent>
<groupId>com.example.foob</groupId>
<artifactId>foob</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>foob-two</artifactId>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>com.example.foob</groupId>
<artifactId>foob-one</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
mvn dependency:list can be run on its own. It appears as if your project is failing because of missing dependencies. Try mvn install first.
how to make one module depends on another module artifact in maven multi-modules
Using this tutorial, I am trying to host a dependency on GitHub and then use the dependency in a separate application.
The dependency is located at:
https://github.com/user/repo/raw/master/release/tld/company/app/1.0.0/app-1.0.0.jar
However. maven keeps going to:
https://github.com/user/repo/raw/master/release/tld/company/app/app/1.0.0/app-1.0.0.pom
In my pom where I'm calling the dependency, I have:
<repositories>
<repository>
<id>tld.company</id>
<name>app</name>
<url>https://github.com/user/repo/raw/master/release/</url>
</repository>
</repositories>
and:
<dependency>
<groupId>tld.company.app</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
</dependency>
In /master/company/release/tld/company/app/maven-metadata-local.xml I have:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>tld.company.app</groupId>
<artifactId>app</artifactId>
<versioning>
<release>1.0.0</release>
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20160233354414</lastUpdated>
</versioning>
</metadata>
In /master/company/release/tld/company/app/1.0.0/app-1.0.0.pom I have:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>tld.company.app</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
<description>POM was created from install:install-file</description>
</project>
What is the reason for the additional /app in the dependency download URL?
The group id should be tld.company, not tld.company.app. This explains your second app.
<dependency>
<groupId>tld.company</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
</dependency>
Basically, when you have a URL from a repository of the following form, this is how it is understood by Maven:
https://someserver.com/.../tld/company/app/1.0.0/app-1.0.0.jar
^---------^ ^-^ ^---^ ^-----------^
groupId | version file name
artifactId
The last part if the file name which is ${artifactId}-${version}.
Before that is the version.
Before that is the artifact id.
And all the path before that are the group id, where slashes are replaced by dots.
When running commands such as
mvn dependency:build-classpath
or
mvn exec:java
Maven is unable to resolve a dependency of one of my modules on another.
[ERROR] Failed to execute goal on project parser-app: Could not resolve dependencies for project project_group:A:jar:0.1-SNAPSHOT: Could not find artifact project_group:B:jar:0.1-SNAPSHOT
The project structure is as follows:
/pom.xml
/A/pom.xml
/B/pom.xml
The parent pom is as follows:
<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>project_group</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>0.1-SNAPSHOT</version>
<name>parent</name>
<modules>
<module>A</module>
<module>B</module>
</modules>
The first child module (the one failing to resolve the dependency):
<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>
<parent>
<groupId>parent_group</groupId>
<artifactId>parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<artifactId>A</artifactId>
<packaging>jar</packaging>
<name>A</name>
<dependencies>
<dependency>
<groupId>parent_group</groupId>
<artifactId>B</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
The second child module (the dependency):
<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>
<parent>
<groupId>parent_group</groupId>
<artifactId>parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<artifactId>B</artifactId>
<packaging>jar</packaging>
<name>B</name>
Have you run mvn clean install at least once on the project to install the dependencies within your local repository?
The Maven reactor is weird that way, it keeps modules around only for certain tasks. When running a build target that only does something for one subproject, then even if Maven builds dependencies first, it does not keep them around in the reactor (sometimes).
Installing to the local repository is a workaround, but it is horrible and should be avoided when possible, because you can easily end up with outdated build results.
A slightly less ugly workaround is to combine two build targets, where the second build target does something harmless, but triggers addition to reactor in all subprojects.
As an example you can combine the task you want with the 'compile' or 'package' tasks.
Also see highest voted answer at
Maven doesn't recognize sibling modules when running mvn dependency:tree
This error might also be caused by Maven being in offline mode.
Sometimes I seem to accidentally enable offline mode in IntelliJ IDEA. To disable it, toggle the Toggle Offline Mode toggle in the Maven Toolbar
or uncheck the Work Offline checkbox in the settings under Build, Execution, Deployment > Build Tools > Maven.
Configuring test-jar in the jar plugin resolved the issue for me:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Afterwards, running mvn clean install works.