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.
Related
If I hardcode repository id/url values directly inside pom.xml as shown below, it's working perfectly fine. I am getting dependencies.
<project ......>
.......
<repositories>
<repository>
<id>myownservice</id>
<url>https://dev.externalrepo.com/account/devenvironment/_packaging/myownservice/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
But if i pass the values from command, I am struggling to pull the dependencies from external repositories (Azure Artifacts).
<?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.company.weather</groupId>
<artifactId>weather-myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.company.weather.service</groupId>
<artifactId>weather-service</artifactId>
<version>1.1.9</version>
</parent>
<properties>
<service.destinationID>${service.destinationID}</service.destinationID>
<service.destinationURL>${service.destinationURL}</service.destinationURL>
</properties>
<repositories>
<repository>
<id>${service.destinationID}</id>
<url>${service.destinationURL}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
Below command used to pass parameters:
mvn package -Dservice.destinationID=myownservice -Dservice.destinationURL=https://dev.externalrepo.com/account/devenvironment/_packaging/myownservice/maven/v1
Below error, look like it's not able to replace parameters dynamically:
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.company.weather:weather-service:1.0-SNAPSHOT: Could not transfer artifact com.company.weather.service:weather-service:pom:1.1.9 from/to ${service.distFeed
Id} (${service.destinationURL}): Cannot access ${service.destinationURL} with type default using the available connector factories: BasicRepositoryConnectorFactory and 'parent.relativePath' points at wrong lo
cal POM # line 11, column 13
How can i make it generalize, that's is, Developers should use it with out any change to their project, DevOps should use mvn package command without change to the command.
Please suggest.
Edited:
added settings.xml, using same file to deploy artifacts to external repository:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:\Users\myusername\.m2\repository</localRepository>
<interactiveMode />
<usePluginRegistry />
<offline />
<pluginGroups />
<servers>
<server>
<id>myownservice</id>
<username>myownserviceusername</username>
<password>dsdsqpyx6cpi3dkb5667andiud3oigi3sdcdkhjv2sgkssdswzfds6azs2aaa</password>
</server>
</servers>
<profiles>
<profile>
<id>distributionManagement</id>
<properties>
<destinationID>myownservice</destinationID>
<destinationURL>https://dev.externalrepo.com/account/devenvironment/_packaging/myownservice/maven/v1</destinationURL>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>distributionManagement</activeProfile>
</activeProfiles>
<mirrors />
<proxies />
</settings>
I added private nexus repository urls in pom.xml to install some dependencies from inhouse nexus repository.
But eclipse still shows "Missing artifact error" messages in pom.xml file
here is command line error messages when I run mvn install command
[ERROR] Failed to execute goal on project diffapi: Could not resolve dependencies for project com.my:diffapi:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.aaa.bbb.poi.jar:poi:jar:5.14.4, com.aaa.bbb.poi.jar:poi-skp-search-client-util:jar:5.14.4, com.aaa.bbb.poi.jar:poi-util:jar:5.14.4, com.aaa.bbb.frame:ndds-log:jar:1.4.6, com.aaa.bbb.frame:ndds-util:jar:1.4.6, com.aaa.bbb.frame:ndds-monitor-agent:jar:1.5.0, com.aaa.bbb.frame:ndds-web-utility:jar:1.5.0, com.aaa.bbb.frame:ndds-context:jar:1.5.0: Failure to find com.aaa.bbb.poi.jar:poi:jar:5.14.4 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
it seems maven only access maven central instead of private nexus repositores
And this is my 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.my</groupId>
<artifactId>diffapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>diffapi</name>
<description>diff api server for rmi and rest result</description>
<properties>
<java.version>1.8</java.version>
<ndds.frame.version>1.5.0</ndds.frame.version>
</properties>
<dependencies>
<dependency>
<groupId>com.aaa.bbb.poi.jar</groupId>
<artifactId>poi</artifactId>
<version>5.14.4</version>
</dependency>
<dependency>
<groupId>com.aaa.bbb.poi.jar</groupId>
<artifactId>poi-skp-search-client-util</artifactId>
<version>5.14.4</version>
</dependency>
<dependency>
<groupId>com.aaa.bbb.poi.jar</groupId>
<artifactId>poi-util</artifactId>
<version>5.14.4</version>
</dependency>
<dependency>
<groupId>com.aaa.bbb.frame</groupId>
<artifactId>ndds-log</artifactId>
<version>1.4.6</version>
</dependency>
<dependency>
<groupId>com.aaa.bbb.frame</groupId>
<artifactId>ndds-util</artifactId>
<version>1.4.6</version>
</dependency>
<dependency>
<groupId>com.aaa.bbb.frame</groupId>
<artifactId>ndds-monitor-agent</artifactId>
<version>${ndds.frame.version}</version>
</dependency>
<dependency>
<groupId>com.aaa.bbb.frame</groupId>
<artifactId>ndds-web-utility</artifactId>
<version>${ndds.frame.version}</version>
</dependency>
<dependency>
<groupId>com.aaa.bbb.frame</groupId>
<artifactId>ndds-context</artifactId>
<version>${ndds.frame.version}</version>
</dependency>
<distributionManagement>
<repository>
<id>AAA-releases</id>
<name>AAA-releases</name>
<url>http://IP:PORT/nexus/content/repositories/AAA-releases/</url>
</repository>
<snapshotRepository>
<id>AAA-snapshots</id>
<name>AAA-snapshots</name>
<url>http://IP:PORT/nexus/content/repositories/AAA-snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
You seem to be confusing repositories where your project will be deployed after building with repositories which are used as sources for the dependencies in your project. You haven't actually specified a custom 3rd party repo, so Maven is giving up after failing to find the artifacts in the central repo. From the Maven documentation:
Whereas the repositories element specifies in the POM the location and manner in which Maven may download remote artifacts for use by the current project, distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed. The repository elements will be used for snapshot distribution if the snapshotRepository is not defined.
So, try adding a <repositories> element which contains the extra repos which you want available for the custom JARs in your build:
<project>
...
<distributionManagement>
<repository>
<id>AAA-releases</id>
<name>AAA-releases</name>
<url>http://IP:PORT/nexus/content/repositories/AAA-releases/</url>
</repository>
<snapshotRepository>
<id>AAA-snapshots</id>
<name>AAA-snapshots</name>
<url>http://IP:PORT/nexus/content/repositories/AAA-snapshots</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<!-- fill in with the actual details of your repo here -->
<repository>
<id>REPO ID</id>
<name>REPO NAME</name>
<url>YOUR URL GOES HERE</url>
</repository>
</repositories>
</project>
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.
I was configure my settings.xml for corp proxy server like this
<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">
<activeProfiles>
<activeProfile>securecentral</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>securecentral</id>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>***.***.***.***</host>
<port>****</port>
<username>******</username>
<password>******</password>
<nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
and got the possibility of downloading dependencies. But if with downloading its ok, when i try to import something to class, idea cant find any downloaded dependency and mark as red all after top domain level. Can to see only base libraries (which was included by default) when i put the dot after org. for example.
In .m2 folder all necessary libraries is downloaded
In settings -> build tools -> maven all as default
Any new dependencies downloads successfully
pom.xml without any errors
<?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>groupId1</groupId>
<artifactId>untitled</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
</project>
Somebody have any idea about that?
Any advise will be helpful!
Thanks a lot guys!
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"