Maven: repository element was not specified in the POM inside distributionManagement? - maven

I am trying to run the command, mvn release:perform, but I get this error:
Failed to execute goal
org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
(default-deploy) on project git-demo:
Deployment failed: repository element
was not specified in the POM inside
distributionManagement element or in
-DaltDeploymentRepository=id::layout::url
parameter
Here's my pom.xml file:
<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.sonatype.blog</groupId>
<artifactId>git-demo</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
<name>git-demo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<scm>
<connection>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</connection>
<url>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</url>
<developerConnection>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</developerConnection>
</scm>
<distributionManagement>
<!-- use the following if you're not using a snapshot version. -->
<repository>
<id>localSnap</id>
<name>RepositoryProxyRel</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>
</repository>
<!-- use the following if you ARE using a snapshot version. -->
<snapshotRepository>
<id>MylocalSnap</id>
<name>RepositoryProxySnap</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>
</project>
Actually I can see the
repository
declaration inside the
distributionManagent
tag.
Here's my settings.xml:
<settings>
<servers>
<server>
<id>localSnap</id>
<username>deployment</username>
<password>****</password>
</server>
<server>
<id>MylocalSnap</id>
<username>deployment</username>
<password>****</password>
</server>
<server>
<id>myserver</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://127.0.0.1:8080/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<properties>
<project.build.sourceEncoding>MacRoman</project.build.sourceEncoding>
<project.reporting.outputEncoding>MacRoman</project.reporting.outputEncoding>
</properties>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Any advice why it complains?

Review the pom.xml file inside of target/checkout/. Chances are, the pom.xml in your trunk or master branch does not have the distributionManagement tag.

I got the same message ("repository element was not specified in the POM inside distributionManagement element"). I checked /target/checkout/pom.xml and as per another answer and it really lacked <distributionManagement>.
It turned out that the problem was that <distributionManagement> was missing in pom.xml in my master branch (using git).
After cleaning up (mvn release:rollback, mvn clean, mvn release:clean, git tag -d v1.0.0) I run mvn release again and it worked.

You can also override the deployment repository on the command line:
-Darguments=-DaltDeploymentRepository=myreposid::default::http://my/url/releases

The ID of the two repos are both localSnap; that's probably not what you want and it might confuse Maven.
If that's not it: There might be more repository elements in your POM. Search the output of mvn help:effective-pom for repository to make sure the number and place of them is what you expect.

For me, this was something as simple as a missing version for my artifact - "1.1-SNAPSHOT"

Related

Add Github Package to maven

A few days ago I created a Github Package for a java library.
Now I wanted to add the dependency from Github Packages to another Maven Project, but I get the following error:
Could not transfer artifact io.geilehner:storyblok-java-sdk:pom:1.0.1 from/to github (https://maven.pkg.github.com/geilix10/): Transfer failed for https://maven.pkg.github.com/geilix10/io/geilehner/storyblok-java-sdk/1.0.1/storyblok-java-sdk-1.0.1.pom 400 Bad Request
My ~/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>geilix10</username>
<password>ghp__ PERSONAL_ACCESS_TOKEN....</password>
</server>
</servers>
</settings>
My pom.xml from the project where I want to add my package.
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/geilix10/</url>
</repository>
</repositories>
and the dependency itself:
<dependency>
<groupId>io.geilehner</groupId>
<artifactId>storyblok-java-sdk</artifactId>
<version>1.0.1</version>
</dependency>
I need the repository tag in the pom.xml because later on GitHub Actions should build this project and otherwise it would not find the package.
Link to the package: https://github.com/geilix10/storyblok-java-sdk/packages/716104?version=1.0.1
#Edit
After adjusting my settings.xml to (as suggested):
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
<servers>
<server>
<id>github</id>
<username>geilix10</username>
<password>TOKEN</password>
</server>
</servers>
<profiles>
<profile>
<id>default</id>
<repositories>
<repository>
<id>github</id>
<name>GitHub Apache Maven Packages</name>
<url>https://maven.pkg.github.com/geilix10/*</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
And my pom.xml :
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/geilix10/storyblok-java-sdk/</url>
</repository>
</repositories>
<dependency>
<groupId>io.geilehner</groupId>
<artifactId>storyblok-java-sdk</artifactId>
<version>1.0.1</version>
</dependency>
And using the command to retrieve the package suggested by Allen D. I receive the following error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.2:get (default-cli) on project regiolix: Couldn't download artifact: org.eclipse.aether.resolution.DependencyResolutionException: Failed to read artifact descriptor for io.geilehner:storyblok-java-sdk:jar:1.0.1: Could not transfer artifact io.geilehner:storyblok-java-sdk:pom:1.0.1 from/to github (https://maven.pkg.github.com/geilix10/): Failed to transfer file https://maven.pkg.github.com/geilix10/io/geilehner/storyblok-java-sdk/1.0.1/storyblok-java-sdk-1.0.1.pom with status code 400 -> [Help 1]
Explicitly add your repository to the URLs.
In your settings.xml:
<repositories>
...
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/geilix10/*</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
...
(Snapshots setting as you need...)
In you POM:
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/geilix10/storyblok-java-sdk/</url>
</repository>
</repositories>
Refer to https://github.com/allen-ball/ganymede for reference.
I was able to download your artifact with:
mvn dependency:get -DremoteRepositories=https://maven.pkg.github.com/geilix10/storyblok-java-sdk -Dartifact=io.geilehner:storyblok-java-sdk:1.0.1
after updating my settings.xml with:
<?xml version="1.0" encoding="UTF-8"?>
<settings ...>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
<servers>
<server>
<id>github</id>
<username>allen-ball</username>
<password>REDACTED</password>
</server>
...
</servers>
<profiles>
<profile>
<id>default</id>
...
<repositories>
...
<repository>
<id>github</id>
<name>GitHub Apache Maven Packages</name>
<url>https://maven.pkg.github.com/geilix10/*</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
...
</repositories>
...
</profile>
</profiles>
</settings>

How to pass repositories/distributionManagement configuration into pom.xml using command line

I attempt to build a CI/CD pipeline that:
runs Swagger codegen that generates a Maven project of the client library.
runs mvn deploy to deploy the client lib to the remote repository.
However, the autogenerated pom.xml does not have the configuration of <repositories> and <distributionManagement>.
I am looking for a Maven-native solution to programmatically add <repositories> and <distributionManagement> configuration to this auto-generated pom.xml.
Autogenerated pom.xml that only lives in the lifecycle of a CI/CD build
<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>
...
<url>https://github.com/swagger-api/swagger-codegen</url>
<description>Swagger Java</description>
<scm>
<connection>scm:git:git#github.com:swagger-api/swagger-codegen.git</connection>
<developerConnection>scm:git:git#github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<licenses>
<license>
<name>Unlicense</name>
<url>http://unlicense.org</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>Swagger</name>
<email>apiteam#swagger.io</email>
<organization>Swagger</organization>
<organizationUrl>http://swagger.io</organizationUrl>
</developer>
</developers>
<build>
...
</build>
<profiles>
...
</profiles>
<dependencies>
...
</dependencies>
<properties>
...
</properties>
</project>
The snippet I want to add into pom.xml:
<repositories>
<repository>
<id>...</id>
<url>...</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>...</id>
<url>...</url>
</repository>
</distributionManagement>
I was able to achieve this by passing a command-line argument to mvn deploy:
mvn deploy -DaltDeploymentRepository=ID:default:URL
ID is the id of the server in your settings.xml
URL is the URL of the deployment endpoint as you would use in distributionManagement/url part of your pom.xml.

Deploy Artefact at nexus Server - error dependencies could not be resolved

I have setup a nexus server and afterwards I had the opinion to simple deploy an artefact to this nexus server. Therefore I created a simple Java project with this pom:
<project xmlns="...">
<modelVersion>4.0.0</modelVersion>
<groupId>MyProject</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
My settings file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<settings ...>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<name>Nexus Public Mirror</name>
<mirrorOf>central</mirrorOf>
<url>http://it-nexus.domain:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Then I have tried to deploy my artefact with:
mvn deploy
and I got this Error:
[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failure to find org.apache.maven.plugins:maven-resources-plugin
:jar:2.6 in http://it-nexus.domain:8081/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of
nexus has elapsed or updates are forced -> [Help 1]
Actually I don't know what I am doing wrong!?
You've got a few things wrong (well, everything really).
First, you can remove profiles and everything under it, along with activeProfiles, from your server.xml file. Next, you need to add a servers entry, containing a server with the id, 'nexus' (assuming you're uploading to the same nexus instance you're using to mirror central), along with a username and password of some sort.
Then you have to have a distributionManagement section in your pom, referencing the same server you've specified in the settings.xml file, and configure the maven-deploy plugin. Documentation for that can be found here. You will also need an scm section.
The actual error you talk about is probably because your nexus server isn't actually configured to proxy/mirror central. Oh, and you should use * as the argument to mirrorOf.

Why my maven project does not pick-up the jar from nexus

I am on Redhat, using jenkins with Nexus Repository Manager OSS 2.12.0-01.
What I am trying to achieve is to download all the jar from nexus.
What, I have accomplished.
Successfully installed nexus 2.12.0-01
This is the content of my maven setting.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Successfully installed 3rd party jar for Ojdbc5 in nexus
content of my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc</groupId>
<artifactId>Test</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Maven Webapp</name>
<url>http://maven.apache.org</url>
<modules>
<module>Project1</module>
<module>Project2</module>
</modules>
<distributionManagement>
<snapshotRepository>
<id>my-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>my-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
</project>
In the above pom.xml there are two projects define. When I build using jenkins, The first project get successfully build. but the second one throws error.
Failed to execute goal on project project2: Could not resolve
dependencies for project com.abc:project2:war:0.0.1-SNAPSHOT: Failure
to find com.oracle:ojdbc5:jar:11.2.0.1 in
http://localhost:8081/nexus/content/groups/public was cached in the
local repository, resolution will not be reattempted until the update
interval of nexus has elapsed or updates are forced -> [Help 1]
Please see the project2 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>
<groupId>com.abc</groupId>
<artifactId>project2</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Maven Webapp</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
<distributionManagement>
<repository>
<id>thirdparty</id>
<url>http://localhost:8081/nexus/content/repositories/thirdparty</url>
</repository>
</distributionManagement>
<dependencies>
<!-- Spring ORM support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.13.RELEASE</version>
</dependency>
<!-- Spring Batch -->
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<!-- ojdbc 5 dependency provide by nexus-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc5</artifactId>
<version>11.2.0.1</version>
</dependency>
<!-- That is creating problem -->
Please do not worry about the above pom.xml I have removed lot of dependency from pom to reduce the size of question. The pom structure is Ok.
Now coming to question. Have I missed any configuration, Why I am getting
Failed to execute goal on project gsdataprocessor: Could not resolve dependencies for project com.globalss.batch:gsdataprocessor:war:0.0.1-SNAPSHOT: Failure to find com.oracle:ojdbc5:jar:11.2.0.1 in http://localhost:8081/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]
This error.
Please help
Update 1: As suggest by user sanigo I have added Thirdpary repository the Public Repository Group
Update 2: Below is the screen-short which shows oracle ojdbc5 is available is public repository.
Your http://localhost:8081/nexus/content/groups/public (Public Repository Group) is mirror of "*", so you should add http://localhost:8081/nexus/content/repositories/thirdparty(Thirdparty repositoy) to the Public Repository Group, you can do this in the Public Repository Configuration tab. Then you can use mvn -U clean install.

Issue pulling SNAPSHOT dependencies from Archiva snapshot repository

I've been setting up an Apache Archiva instance as both a proxy to Maven Central and to capture our development snapshots. I've managed to setup the proxy and I can deploy artifacts to the Archiva snapshot repository however I cannot pull artifacts from the snapshot repositories to use in other projects.
Relevant parts of pom.xml (dependant project)
<project>
<!-- Excluded detail -->
<dependency>
<groupId>uk.abc</groupId>
<artifactId>ABC</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<!-- Excluded detail -->
<distributionManagement>
<repository>
<id>archiva.snapshots</id>
<name>Snapshot Repository</name>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/snapshots</url>
</repository>
</distributionManagement>
<!-- Excluded detail -->
</project>
My ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>archiva.snapshots</id>
<username>username</username>
<password>xxx</password>
</server>
<server>
<id>archiva.internal</id>
<username>username</username>
<password>xxx</password>
</server>
</servers>
<mirrors>
<mirror>
<id>archiva.internal</id>
<mirrorOf>central</mirrorOf>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/internal</url>
</mirror>
<mirror>
<id>archiva.snapshots</id>
<mirrorOf>snapshots</mirrorOf>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/snapshots</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>archiva.internal</id>
<name>Archiva Managed Internal Repository</name>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>archiva.snapshots</id>
<name>Archiva Managed Internal Repository</name>
<url>https://xxx.xxx.xxx.xxx/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
When I build the dependant project I cannot reference classes (public access).
Just to note that I can browse the snapshots repository and I know the war file is there.
Any ideas?
It turns out that you cannot use the "war" dependency type and expect to be able to reference the contained classes. You can however create an additional jar (create both war and jar) containing the classes:
http://maven.apache.org/plugins/maven-war-plugin/faq.html#attached
You can the use the type "jar" when pulling in the dependency... in my case:
<dependency>
<groupId>uk.abc</groupId>
<artifactId>ABC</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
I think therefore the question is a bit misleading... the dependency was being pulled from Archiva but was not of an accessible type.
You are probably not activating the profile correctly
before the profile in settings.xml put something like
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
Remember this about activeByDefault
This profile will automatically be active for all builds unless
another profile in the same POM is activated using one of the
previously described methods. All profiles that are active by default
are automatically deactivated when a profile in the POM is activated
on the command line or through its activation config.
if you want to confirm if this is the issue, look at the active profiles by running help:active-profiles

Resources