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
Related
I have multiple spring boot projects, every project is independent and has its own CICD pipeline.
These projects need some common classes, I have created a separate project with common classes.
Parent
pom.xml (with packaging)
lib-project
pom.xml
project-1
pom.xml
project-2
pom.xml
I can build project easily from the parent directory, it builds all the projects
parent$ mvn clean package
it generates all the jar files and put them in their respective target folder of projects
My problem is I can't initiate this at the parent level, this has to be initiated from within each project from its own pipeline.
and
I cannot use any local or remote repository, to put the dependent jar in m2 using mvn clean install and then refer to it as dependency
I want to build it from the relavent project directory
parent/project-1$ mvn clean package
it shows following error:
Could not resolve dependencies for project com.test.multiple:project-1:jar:0.0.1-SNAPSHOT: Could not find artifact com.test.multiple:lib-project:jar:0.0.1-SNAPSHOT
My expectation stepwise on compilation of project-1
Check if there is a dependency for project-1
Go to ../lib-project
Compile and build it in target folder (or anywhere relative to our project)
Add this generated jar to "project-1" dependency
Compile and build the "project-1" jar file.
Parent Pom Configurations
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test.multiple</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>lib-project</module>
<module>project-1</module>
</modules>
</project>
** Lib project pom **
<project ...>
<parent>
<groupId>com.test.multiple</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.test.multiple</groupId>
<artifactId>lib-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lib-project</name>
<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>
</dependencies>
</project>
Project-1 pom
<project ...>
<parent>
<groupId>com.test.multiple</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.test.multiple</groupId>
<artifactId>project-1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>project-1</name>
<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>com.test.multiple</groupId>
<artifactId>lib-project</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I have multiple spring boot projects, every project is independent and has its own CICD pipeline.
These projects need some common classes, I have created a separate project with common classes.
Congratulations, your projects are not independent any more!
Given the definitions above, here are the dependencies:
lib-project depends on parent;
project-1 depends on parent;
project-1 depends on lib-project.
Please check Introduction to the POM and Guide to Working with Multiple Modules for the discussion on the dependencies in Maven projects.
I cannot use any local or remote repository, to put the dependent jar in m2 using mvn clean install and then refer to it as dependency
Given this limitation, and dependencies listed above, the POMs and source files of all the projects have to be present on the disk for build purposes. The build process has to start from the parent folder. The build process has to build all modules at once.
Also, please consider using mvn clean verify instead of mvn clean install to avoid populating the local repository with the artifacts you are building.
A maven project isn't designed to build its dependencies on demand. However, jenkins can be configured to build downstream projects when changes are pushed to an upstream dependency.
I have also worked around this by using the -pl option on a parent pom in the relevant jenkinsfile to build a subset of the child projects
Jenkinsfile
clone parent project
mvn clean package -pl core,deployable
I have two projects - A and B, where A is dependent on B. I package B as jar and deploy it on a maven server (artifactory), and then include that jar as a normal dependency on project A in pom file. jar file of B shows up in the Maven Dependencies of project A, but dependencies of project B are not shown in dependency hierarchy. It is causing class not found exception for dependencies of B.
However, my project A and B and in same eclipse workspace. When I open project B, project A starts referencing the project B from the workspace instead of remote repository and everything works well.
This question - Maven. Transitive dependencies was closest to my problem, but dependencies of my project B are NOT optional.
Whats going wrong here?
POM for project B
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>utils</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>jar</packaging>
<name>utils</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- Following doesn't get added to project A -->
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>
POM for project A
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>core-app</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>jar</packaging>
<name>core-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.myapp</groupId>
<artifactId>utils</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
</dependencies>
</project>
I am using maven quickstart archetype. Project structure of my projects is (which I package as jar):
project-name
src/main/java
src/test/java
pom.xml
To successfully resolve transitive dependencies, project B's jar and pom.xml must be accessible in the Maven repository. When deploying artifacts to a remote repository, be sure both the jar and pom.xml are deployed and available for download.
With the requisite files deployed to the remote repository, use the command line to build project A. Specify a build Maven target to trigger the downloading of all dependencies into the local Maven repository. Something like mvn compile or mvn package will trigger the downloads and successfully build project A.
Once, project B's jar and pom.xml are in the local Maven repository, update the Maven projects in Eclipse and they will rebuild and resolve the dependencies correctly.
I have a multi module project with below hierarchy :
parent-build project pom.xml
...
<groupId>com.my.project</groupId>
<artifactId>parent-build</artifactId>
<packaging>pom</packaging>
<name>parent-build</name>
<version>${version.product}</version>
<properties>
<version.product>1.0</version.product>
</properties>
...
build-all project pom.xml
...
<parent>
<artifactId>parent-build</artifactId>
<groupId>com.my.project</groupId>
<version>${version.product}</version>
<relativePath>../parent-build/pom.xml</relativePath>
</parent>
<groupId>com.my.project</groupId>
<packaging>pom</packaging>
<modules>
<module>../child-1</module>
<module>../child-2</module>
</modules>
...
child-2 project pom.xml
...
<parent>
<artifactId>parent-build</artifactId>
<groupId>com.my.project</groupId>
<version>${version.product}</version>
<relativePath>../parent-build/pom.xml</relativePath>
</parent>
<groupId>com.my.project</groupId>
<artifactId>child-2</artifactId>
<packaging>jar</packaging>
<version>${version.product}</version>
...
<dependencies>
<dependency>
<groupId>com.my.project</groupId>
<artifactId>child-1</artifactId>
<version>${version.product}</version>
</dependency>
...
</dependencies>
...
child-1 project pom.xml
...
<parent>
<artifactId>parent-build</artifactId>
<groupId>com.my.project</groupId>
<version>${version.product}</version>
<relativePath>../parent-build/pom.xml</relativePath>
</parent>
<groupId>com.my.project</groupId>
<artifactId>child-1</artifactId>
<packaging>jar</packaging>
<version>${version.product}</version>
...
I want to build all jars with same version and this version should be specified at single place.
I declared a property in parent-build pom.xml
Now when I do mvn clean install on build-all project , it builds all projects in specified order of modules.
That is fine.
But in some cases , I want to build child-2 project only.
i.e ,lets say I do some changes in child-2 project and want to build only this project.
The problem with this scenario is , it cannot find the property value version.product
Edit:
Below is the error I am getting when building child-2 project
Could not transfer artifact com.my.project:parent-build:pom:${version.product} from/to central (http://repo1.maven.org/maven2): Illegal character in path at index 66: http://repo1.maven.org/maven2/com/my/project/parent-build/${version.product}/parent-build-${version.product}.pom
Please help.
Thanks in advance.
Firstly I would urge against this, but I know you may have a module that is not working properly yet etc. In the past I have used profiles in the parent pom to control the modules list:
<profiles>
<profile>
<id>all</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>1</module>
<module>2</module>
<module>3</module>
<module>4</module>
</modules>
</profile>
<profile>
<id>profile1</id>
<modules>
<module>1</module>
<module>2</module>
<module>3</module>
</modules>
</profile>
</profiles>
then for :
1) mvn clean install - you will get all modules
2) mvn clean install -Pprofile1 you will only get modules 1,2 & 3.
flatten-maven-plugin
This is what I want.
This plugin will replace your version specified in property, with actual property value in all effective pom.xml.
So later if you build any child separately, it will build successfully.
Cheers
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.
I am trying to create a maven multi-module project. the project is created successfully but when I am trying to use one module as a dependency of another module, it throws an exception. When I create a module using eclipse, I was selecting packaging as a jar, but when the module is created, the packaging tag was not mention in child pom.xml and I manually insert the packaging tag as a jar.
following is my parent 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.netsol</groupId>
<artifactId>empirecl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
-------------------------
<modules>
<module>empirecl-web</module>
<module>empirecl-dao</module>
<module>empirecl-service</module>
<module>empirecl-api</module>
</modules>
Dao Child 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>
<groupId>com.netsol</groupId>
<artifactId>empirecl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>empirecl-dao</artifactId>
<packaging>jar</packaging>
<name>empirecl-dao</name>
------------------------
Service Child 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>
<groupId>com.netsol</groupId>
<artifactId>empirecl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>empirecl-service</artifactId>
<packaging>jar</packaging>
<name>empirecl-service</name>
<dependencies>
<dependency>
<groupId>com.netsol</groupId>
<artifactId>empirecl-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
------------------------------------------
The Dao module maven clean and install successfully, but when i trying to use service module, it will generate an following exception:
[ERROR] Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Could not find artifact com.netsol:empirecl:pom:0.0.1-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT
I am trying the find to solution from web, but still the solution is not found. In eclipse when i open the Dependency Hierarchy of service module, it shown the DAO module as a folder not jar. below is the screen shot of Dependency Hierarchy of service module.
In case anybody comes back to this, I think the problem here was failing to install the parent pom first, which all these submodules depend on, so the Maven Reactor can't collect the necessary dependencies to build the submodule.
So from the root directory (here D:\luna_workspace\empire_club\empirecl) it probably just needs a:
mvn clean install
(Aside: <relativePath>../pom.xml</relativePath> is not really necessary as it's the default value).
In my case I forgot it was packaging conflict jar vs pom. I forgot to write
<packaging>pom</packaging>
In every child pom.xml file
My solution was to insert <packaging>pom</packaging> between artifactId and version
<groupId>com.onlinechat</groupId>
<artifactId>chat-online</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>server</module>
<module>client</module>
<module>network</module>
</modules>
This what worked for me -
Go to Java build path --> Order and Export(check JRE system libraries and maven dependencies) in my case these 2 were unchecked.
My solution:
remove all projects in current workspace
import all again
maven update project (Alt + F5) -> Select All and check Force Update of Snapshots/Releases
maven build (Ctrl + B) until there is nothing to build
It worked for me after the second try.
For me, adding the following block of code under <dependency management><dependencies> solved the problem.
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b06</version>
</dependency>
Check with your VPN connection, if you are working in home.
Delete or close all other projects, and restart netbeans IDE, and try again.