I've had a fair amount of help with my Maven code and I'm currently trying to have my project deploy to a project determined by a variable. Here is my 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>maven.Test</groupId>
<artifactId>Hello</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Artifactory</name>
<url>http://artifactory:8081/artifactory/webapp/home.html?0</url>
<repositories>
<repository>
<id>parentPomLocation</id>
<name>Artifactory</name>
<url>http://artifactory:8081/artifactory/dev</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<parent>
<groupId>dev</groupId>
<artifactId>company-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
</project>
So my pom first pulls the parent Pom.xml from artifactory and checks it for it's distribution management. Here is the parent 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev</groupId>
<artifactId>company-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<distributionManagement>
<repository>
<id>Artifactory</id>
<name>Artifactory-releases</name>
<url>http://artifactory:8081/artifactory/${repo}</url>
</repository>
<snapshotRepository>
<id>Artifactory</id>
<name>Artifactory-snapshots</name>
<url>http://artifactory:8081/artifactory/${repo}</url>
</snapshotRepository>
</distributionManagement>
</project>
The parent Pom.xml's distribution url is determined through a variable I assign, this is the command line I run.
mvn deploy -D$repo=integration
But no matter what it always deploys to dev and not integration.
Related
I am trying to build a discord application but it can't access the JDA latest version.
Error:
Dependency 'net.dv8tion:JDA:4.2.1_255' not found
<?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.example</groupId>
<artifactId>Discord_BOT</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.1_255</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
</repositories>
</project>
Not able to add parent tag in pom.xml just like below. It keeps giving me an error saying "Project 'org.springframework.boot:spring-boot:2.3.2.RELEASE' not found
Inspection info: Inspects a Maven model for resolution problems." Could someone help please?
<?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.learning.springboot</groupId>
<artifactId>SpringBootApplication</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<artifactId>spring-boot</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.3.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
</dependency>
</dependencies>
</project>
Check first if repository is part of your project:
On maven central, I see:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
So, as in here, add:
<project>
<!------ others lines -->
<pluginRepositories>
<pluginRepository>
<id>repository.spring.release</id>
<name>Spring GA Repository</name>
<url>https://repo.spring.io/plugins-release/</url>
</pluginRepository>
</pluginRepositories>
</project>
Or, in your case, a repository, as in the same thread:
<repository>
<id>repository.springframework.maven.release</id>
<name>Spring Framework Maven Release Repository</name>
<url>http://maven.springframework.org/milestone/</url>
</repository>
I have a Pom.xml I was wondering if there is a way to have the Pom download the Parent pom from somewhere then reference the parent Pom.
Edit: I'm having issue with the parent pom, this is the parent Pom I have
<?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>dev</groupId>
<artifactId>company-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<distributionManagement>
<repository>
<id>Artifactory</id>
<name>Artifactory-releases</name>
<url>http://artifactory:8081/artifactory/dev</url>
</repository>
<snapshotRepository>
<id>Artifactory</id>
<name>Artifactory-snapshots</name>
<url>http://artifactory:8081/artifactory/dev</url>
</snapshotRepository>
</distributionManagement>
</project>
I have uploaded the parent Pom.xml to artifactory, here is my 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>maven.Test</groupId>
<artifactId>Hello</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Artifactory</name>
<url>http://artifactory:8081/artifactory/webapp/home.html?0</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<parent>
<groupId>dev</groupId>
<artifactId>company-parent</artifactId>
<version>1.0.0</version>
</parent>
</project>
But when I run it I get this error
[ERROR] Non-resolvable parent POM for maven.Test:Hello:1.0-SNAPSHOT: Could n
ot find artifact dev:company-parent:pom:1.0.0 in central (https://repo.maven.a
pache.org/maven2) and 'parent.relativePath' points at wrong local POM # line 22,
column 9 -> [Help 2]
How do I have my Pom find the artifact in my artifactory instance?
You parent pom should be pom with packaging type of pom. e.g:
<?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.example</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
</project>
The pom, mentioned above, you can deploy to artifactory and after that you can reference it as parent pom in the child pom. e.g:
<?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>
<artifactId>parent</artifactId>
<groupId>org.example</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>child</artifactId>
<repositories>
<repository>
<id>Artifactory-Releases</id>
<url>http://artifactory:8081/artifactory/dev</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>Artifactory-Snapshots</id>
<url>http://artifactory:8081/artifactory/dev</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
</project>
When I run mvn deploy on a project where the version of a dependency in the child pom is defined as a property in the parent pom, the version number is not expanded in the deployed artifact.
In this example ${spring.version} is not expanded. Can I make maven expand the version property?
Parent 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>TestProject</groupId>
<artifactId>TestProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>test</module>
</modules>
<properties>
<spring.version>3.2.2.RELEASE</spring.version>
</properties>
<distributionManagement>
<snapshotRepository>
<id>dips_snapshot</id>
<url>http://mavenrepo.dips.local/repository/dips_snapshot</url>
</snapshotRepository>
</distributionManagement>
</project>
Child 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>TestProject</groupId>
<artifactId>subproject</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>TestProject</groupId>
<artifactId>TestProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
Deployed 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>TestProject</groupId>
<artifactId>subproject</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>TestProject</groupId>
<artifactId>TestProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
It seems you need to install locally (or even deploy) the parent pom. To do so you can simply run:
mvn clean install -N
in your parent project directory. The -N option is not mandatory, it only stop the recursion (so it will be very fast since only your parent pom will installed)
I prefer a different project organization, where parenthood and aggregation are separated. I use an aggregator project which contains my plain projects as modules and a parent project which is also a module of my aggregator project. This parent project is shared between all the plain projects and the aggregator. My parent and plain projects are stored in subdirectories of the aggregator project directory and the relativePath of each parent element is set accordingly.
This organization better separates concerns and ensures that inter-project dependencies are handled correctly, as long as you perform your builds from the aggregator project directory.
How do I update properties during a mvn release:prepare
My pom.xml looks like this:
<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.mycompany.proj</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<proj-dependency-version>1.0.0-SNAPSHOT</proj-dependency-version>
</properties>
<dependencies>
<dependency>
<groupId>my.proj.dependency</groupId>
<artifactId>proj-dependency</artifactId>
<version>${proj-dependency-version}</version>
</dependency>
</dependencies>
</project>
I found a solution via the maven version:update_properties plugin