I have build a maven project A inside that build.xml include all test dependencies import using another pom.
when I trying to include that maven project A to gradle project B
It gives error.
I try with [--info] first it tries correct repository url and updating jar [Cached resource is up-to-date]. But finally it tries others and throws error.
How to pass profile name form gradle build file?
helps are appreciated.
Project A -> Maven Build - pom.xml
<groupId>com.spring.test</groupId>
<artifactId>Rest</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Project</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<JUnitBOM.version.number>1.0.0</JUnitBOM.version.number>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- Components -->
<dependency>
<groupId>com.test</groupId>
<artifactId>JUnitBOM</artifactId>
<version>${JUnitBOM.version.number}-${project.qualifier}
</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<profile>
<id>AUAT</id>
<properties>
<env>uat</env>
<project.qualifier>SNAPSHOT</project.qualifier>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
Project B -> gradle build - build.gradle
apply plugin: 'java'
apply plugin: 'maven'
group = "com.spring.integration"
status = 'integration'
version = '1.0.0'
sourceCompatibility = 1.7
repositories {
maven { url "http://repo1" }
maven { url "http://maven.springframework.org/release" }
maven { url "http://maven.restlet.org" } }
dependencies {
compile group:'com.spring.test', name:'Rest', version:'1.0.0-SNAPSHOT', classifier: 'AUAT'
compile group:'org.restlet.jee', name:'org.restlet', version:'2.2'
compile group:'org.restlet.jee', name:'org.restlet.ext.servlet',version:'1.1'
compile group:'org.springframework', name:'spring-web', version:'3.2.1.RELEASE'
compile group:'org.slf4j', name:'slf4j-api', version:'1.7.2'
compile group:'ch.qos.logback', name:'logback-core', version:'1.0.9'
testCompile group:'junit', name:'junit', version:'4.11'
}
Error Message
Could not resolve all dependencies for configuration ':compile'.
> Could not resolve com.spring.test:Rest:1.0.0-SNAPSHOT.
Required by:
com.spring.test:0.1.0-SNAPSHOT
> Could not resolve com.test:JUnitBOM:1.0.0-${project.qualifier}.
> java.lang.IllegalArgumentException (no error message)
> java.lang.IllegalArgumentException (no error message)
> java.lang.IllegalArgumentException (no error message)
> Could not HEAD 'http://maven.restlet.org/com/spring/test/Rest/1.0.0-SNAPSHOT/Rest-1.0.0-SNAPSHOT.pom'. Received status code 409 from server: Conflict
You can make use of Gradle maven settings plugin https://plugins.gradle.org/plugin/net.linguica.maven-settings.
With the maven settings plugin, you can pass the activeProfiles, custom maven settings file.
Related
I have one interesting question about resolving dependencies versions by gradle. Here is my situation. I deployed my libraries to nexus. In this process I used the flatten-maven-plugin and resolveCiFriendliesOnly flattenMode. As result I have parent pom file and child pom files in nexus.
parent pom file from source:
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>${revision}${changelist}</version>
<packaging>pom</packaging>
<properties>
<revision>0.0.1</revision>
<changelist>-SNAPSHOT</changelist>
<version.base>${revision}${changelist}</version.base>
<example-child.version>${version.base}</example-child.version>
<example-child-dependency.version>${version.base}</example-child-dependency.version>
</properties>
child pom file from source
<parent>
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>${revision}${changelist}</version>
<relativePath>..</relativePath>
</parent>
<artifactId>example-child</artifactId>
<version>${example-child.version}</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>ru.example</groupId>
<artifactId>example-child-dependency</artifactId>
<version>${example-child-dependency.version}</version>
</dependency>
</dependencies>
parent pom file from nexus
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<version.base>0.0.1-SNAPSHOT</version.base>
<revision>0.0.1</revision>
<changelist>-SNAPSHOT</changelist>
<example-child.version>${version.base}</example-child.version>
<example-child-dependency.version>${version.base}</example-child-dependency.version>
<properties>
child pom file from nexus
<parent>
<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>ru.example</groupId>
<artifactId>example-child</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>ru.example</groupId>
<artifactId>example-child-dependency</artifactId>
<version>${example-child-dependency.version}</version>
</dependency>
</dependencies>
After that I try to build java application with gradle. In build.gradle file of this application I have such line:
dependencies {
implementation("ru.example:example-child:0.0.1-SNAPSHOT")
}
And build fails with error:
> Task :java_application:compileJava
Resolving global dependency management for project 'java_application'
Errors occurred while build effective model from /u01/jenkins_slave/.gradle/caches/modules-
2/files-2.1/ru.example/example-child/0.0.1-
SNAPSHOT/809129e53f76bfb7b6a141e9aeb8ffb1a692e76c/example-child-0.0.1-SNAPSHOT.pom:
'dependencies.dependency.version' for ru.example:example-child-dependency:jar must be a
valid version but is '${example-child-dependency.version}'. in ru.example:example-
child:0.0.1-SNAPSHOT
Why gradle doesn't resolve placeholder of child project dependency?
gradle appearently does not evaluate ${example-child-dependency.version} and you might have to build with mvn in order to produce consumable/static *.pom for gradle. I mean, most likely mvn would evaluate *.pom, while gradle doesn't.
And that might rather be:
<artifactId>example-child-dependency</artifactId>
<version>${version.base}</version>
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
The whole project dependencies are looking like this:
- parent
- child-a
- pom.xml
- child-b
- src.main.java.resources
- mybatis-generator.xml
- pom.xml
- pom.xml
parent, pom.xml
<project>
<packaging>pom</packaging>
<modules>
<module>child-a</module>
<module>child-b</module>
</modules>
</project>
child-b, pom.xml
<project>
<packaging>jar</packaging>
<parent>
<artifactId>parent</artifactId>
<relativePath>../</relativePath>
</parent>
<dependencies>
<dependency>
<artifactId>child-a</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<!-- other configs -->
</plugin>
</plugins>
</build>
</project>
When packaging child-b project/module solely,all dependencies were handled properly(child-a was imported as expected).
Problem:
When I'm trying to run mvn mybatis-generator:generate in the directory of child-b:
Error: Failed to execute goal on project service_a: Could not resolve dependencies for project xx.xx.child-b:jar:1.0-SNAPSHOT: Could not find artifact xx.xx.child-a:jar:1.0-SNAPSHOT -> [Help 1]
When you run maven from a nested project, it will only succeed if all the dependencies are available in your local repo. I can reproduce this if I delete a dependency from my local repo and try it on one of my projects.
Snapshot dependencies add another level of complexity in that they expire - meaning maven will look for a newer version if the version in your local repo is not considered current. They may be why a package ran at some point, but later on another maven commend like running the generator failed.
Bottom line...when snapshot dependencies are involved with nested projects, the only reliable way to run maven is to run the entire project (run maven from the parent directory).
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 the following scenario:
I want to use a project of mine (hosted on bintray.com) in another project of mine.
I set up a maven repository, uploaded artifacts and pom files and then was able to utilize the jar file(s) uploaded to the bintray maven repo just fine, with the following build.gradle file:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'randers.test.usageTest.UsageTest'
repositories {
maven { url 'http://dl.bintray.com/randers00/NotEnoughVocab' }
jcenter()
}
dependencies {
compile(group: 'randers.notenoughvocab.core', name: 'notenoughvocab-core', version: '0.0.1', ext: 'jar')
}
jar {
manifest {
attributes "Main-Class": mainClassName
}
}
This build file successfully equips the project with my core library and even makes sources, etc. available in the IDE (IntelliJ IDEA I use)
The problem is: The core itself uses libraries, which are not gotten by gradle.
This is the pom file that is on bintray:
<?xml version="1.0" encoding="UTF-8"?>
<project 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>randers.notenoughvocab.core</groupId>
<artifactId>notenoughvocab-core</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<licenses>
<license>
<name>GNU General Public License, Version 3.0</name>
<url>http://www.gnu.org/licenses/gpl.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<contributors>
<contributor>
<name>Ruben Anders</name>
<email>RAnders00#users.noreply.github.com</email>
<url>https://github.com/RAnders00</url>
</contributor>
</contributors>
</project>
I looked at other projects on bintray and their pom files look similar.
Declaring the dependecy the traditional and simple way works fine:
compile 'randers.notenoughvocab.core:notenoughvocab-core:0.0.1'
It doesn't work when you specify ext: 'jar', because that is used to download a single artifact. From the user guide:
Artifact only notation
As said above, if no module descriptor file can be found, Gradle by default downloads a jar with the name of the module. But sometimes, even if the repository contains module descriptors, you want to download only the artifact jar, without the dependencies. [14] And sometimes you want to download a zip from a repository, that does not have module descriptors. Gradle provides an artifact only notation for those use cases - simply prefix the extension that you want to be downloaded with '#' sign:
Example 50.5. Artifact only notation
build.gradle
dependencies {
runtime "org.groovy:groovy:2.2.0#jar"
runtime group: 'org.groovy', name: 'groovy', version: '2.2.0', ext: 'jar'
}