Not able to download Jars from nexus - maven

I have project A which is dependency of project B. Since project B should get latest jar version of Project A . I purge Project A jar from local so Project B will get Project A jar from nexus since it has been deleted from local.
I can see in the logs that It can download jar from nexus . but still getting pom for jar is missing
below are the logs
Downloading from : ://10.245.240.43:8081/nexus/repository/maven-snapshots/com/sgl/smartpra/master/model/smartpra-master-model/0.0.1-SNAPSHOT/smartpra-master-model-0.0.1-20191126.094645-53.jar
[INFO] Downloaded from : ://10.245.240.43:8081/nexus/repository/maven-snapshots/com/sgl/smartpra/master/model/smartpra-master-model/0.0.1-SNAPSHOT/smartpra-master-model-0.0.1-20191126.094645-53.jar (183 kB at 1.7 MB/s)
The POM for com.sgl.smartpra.master.model:smartpra-master-model:jar:0.0.1-20191126.094645-53 is missing, no dependency information available
You can see that it can able to pull jars from nexus still getting artifact missing.
I added maven plugin to perge dependent jars from local so it will pull latest jar from nexus
refer Below snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>purge-local-dependencies</id>
<phase>process-sources</phase>
<goals>
<goal>purge-local-repository</goal>
</goals>
<configuration>
<includes>
<include>com.sgl.smartpra.global.master.model:smartpra-global-master-model</include>
<include>com.sgl.smartpra.batch.global.model:smartpra-batch-global-model</include>
<include>com.sgl.smartpra.master.model:smartpra-master-model</include>
<include>com.sgl.smartpra.exception.txn.model:smartpra-exception-txn-model</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Below is nexus repository configuration for downloading jars from nexus
Please check below code
refer Below snippet
I have project A which is dependency of project B. Since project B should get latest jar version of Project A . I purge Project A jar from local so Project B will get Project A jar from nexus since it has been deleted from local.
<repositories>
<repository>
<id>maven-group</id>
<url>**strong text**/10.245.240.43:8081/nexus/repository/maven-group/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>

Related

Pushing artifacts to the Nexus using Jenkins maven-release-plugin

In my Jenkins dashboard, I'm using maven-release-plugin (v0.16.2) to perform a maven release to Nexus repository. I have some issues while using this plugin.
Issue 1:
As shown in the image, it uses <project_name>-<release_version> as the SCM default tag. But I want to change it as v<release_version> value. Therefore, I have added the following change into my project pom.xml file's plugin section.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
But still, it uses the aforementioned default tag. Is there any other configuration I have to do in Jenkins or pom.xml file?
Issue 2:
I have configured my pom.xml file with distributionManagement section to push my built artifact to the Nexus repository as follows.
<distributionManagement>
<repository>
<id>releases</id>
<name>Release Distribution Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
With this configuration, Jenkins pushes all the project built artifacts (packaging JAR artifact + dependency XML artifacts in M2) to the given Nexus repository successfully. But in my case, I want to deploy only the JAR file to the Nexus repository (excluding other dependency XML files). Is it possible to do with this Jenkins maven release plugin? Deploy only a specific file or directory?

How do I include a Maven plugin from a local repository?

I have a custom plugin that compresses files that I need to include in my maven build. So I have included this plugin in my pom.xml:
<build>
// Other tags
<plugin>
<groupId>someGroupId</groupId>
<artifactId>somePlugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Since it is a custom plugin, it is not available in any public Maven repository. So whenever I try to build, I get an error message saying:
Failed to read artifact .....
even though I have added it to my local repository. How can I refer to this plugin that is in my local repository?
If you mean local repository in the classic sense, make sure that you installed your plugin jar correctly. Install it to your local repository again with the following command:
mvn install:install-file -Dfile=/some/path/somePlugin.jar -DgroupId=someGroupId -DartifactId=somePlugin -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true
You should then be able to use your plugin in your Maven build.
If you mean local in the sense of some locally hosted repository, you need to specify the repository containing your artifact as a pluginRepository. Add the following to the top level of your pom.xml:
<pluginRepositories>
<pluginRepository>
<id>some-repo</id>
<name>Some Repository</name>
<url>http://some.host/some/path</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

maven does not change the snapshot jar file in local repository

We config jfrog artifactory successfully and create a pom.xml to build and deploy our basic jar files into it as snapshot. then we configure another project to get those jar files from repository and it did successfully too, then we try to change basic libraries and deploy it again as the same snapshot name, and it did correctly but when we want to get those libraries again, maven does not change the basic libraries in local repository, unless we change the version of the snapshot but we don't want to do it.
deploy pom.xml configuration file
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>2.2.2</version>
<inherited>false</inherited>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>publish</goal>
</goals>
<configuration>
<deployProperties>
<gradle>awesome</gradle>
</deployProperties>
<artifactory>
<includeEnvVars>true</includeEnvVars>
<timeoutSec>60</timeoutSec>
<propertiesFile>publish.properties</propertiesFile>
</artifactory>
<publisher>
<contextUrl>{{ARTIFACTORY_CONTEXT_URL|"http://tls.local:9081/artifactory"}}</contextUrl>
<username>admin</username>
<password>AP5PqkrxgwKVMBeY6wxPYr66R3M</password>
<excludePatterns>*-tests.jar</excludePatterns>
<repoKey>libs-release-local</repoKey>
<snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
</publisher>
<buildInfo>
<buildName>plugin-demo</buildName>
<buildNumber>{{DRONE_BUILD_NUMBER|TRAVIS_BUILD_NUMBER|CI_BUILD_NUMBER|BUILD_NUMBER}}
</buildNumber>
<buildUrl>{{DRONE_BUILD_URL|CI_BUILD_URL|BUILD_URL}}</buildUrl>
</buildInfo>
<licenses>
<autoDiscover>true</autoDiscover>
<includePublishedArtifacts>false</includePublishedArtifacts>
<runChecks>true</runChecks>
<scopes>compile,runtime</scopes>
<violationRecipients>build#organisation.com</violationRecipients>
</licenses>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
third party pom.xml configuration file:
<repository>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://tls.local:9081/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
How can we achieve our goal?
first we must configure our jfrog repository's maven snapshot version behavior to unique and check handle releases and handle snapshot and then delete completely our local repository's snapshot

maven release:prepare not deploying the projects with release version

I have a flat project structure with multiple projects.
I am using Nexus for internal repository and SVN for Source code management.
I am able to deploy the SNAPSHOT build of my project.
In my parent pom i have added the maven release plug-in:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
</plugin>
and the distribution info:
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
When I am doing a mvn release:prepare, the artifacts with the release versions are not getting deployed to repo. So if I have a project A with dependency on project B. Project A is not able to get the artifact of B with the release version.
The release:prepare by default calls "clean" and "verify" goals which simply tries to compile and run test. So nothing is deployed to your remote repository nor installed in your local repository.
To handle dependencies in multi-module projects with the new release version you need to have things installed in local repository during release:prepare, so change the default goals to "clean" and "install" with the preparationGoals property.
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<preparationGoals>clean install</preparationGoals>
</configuration>
</plugin>
You can add any goals you would need during your build.
The actual deployment to remote repository will be done by the release:perform goal.
Laurent

Why is Maven (incorrectly?) deploying my SNAPSHOT to both the release and snapshot repositories?

I'm currently experiencing a problem while trying to set up a project to deploy to an internal nexus repository. Since I'm rather new to Maven in general, I expect that there is just something that I'm not really comprehending in how to set up distribution management.
The basic issue is that when I execute "mvn deploy" the artifact is being successfully deployed to the snapshot repository, but Maven is also attempting to deploy it to the release repository, which is failing ... as it should. My understanding of my current configuration is that it should NOT be deploying it to the release repository as well.
I've included the various configuration elements below, but I'm wondering if I actually am supposed to be managing the section with a profile so that snapshot builds only have defined, and release builds have only defined.
Any help/clarification on this would be incredibly appreciated.
I have the following in my POM for distribution management:
<distributionManagement>
<repository>
<id>internal-releases</id>
<name>Internal Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>internal-snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
Elsewhere in the POM I have the following set up to allow use of these repositories to obtain artifacts:
<repositories>
<repository>
<id>internal-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>internal-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- other repos, etc, etc -->
</repositories>
I have the correct settings in my settings.xml to provide credentials to be able to publish to this test nexus instance running on my computer, and it is in fact successfully deploying the snapshot.
The problem is that it also tries to deploy the snapshot to the release repository, which is configured to disallow snapshots.
The output from "mvn deploy" includes the following:
[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from internal-snapshots
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-8.war
405K uploaded (service-1.0.0-20101104.170338-8.war)
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT'
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'artifact com.internal:service'
[INFO] Uploading project information for service 1.0.0-20101104.170338-8
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
[INFO] repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT' could not be found on repository: remote-repository, so will be created
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar. Return code is: 400
The log from Nexus contains the following (as I would expect it to):
jvm 1 | 2010-11-04 13:03:39 INFO [p-759477796-118] - o.s.n.p.m.m.M2Repos~ - Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
jvm 1 | 2010-11-04 13:03:39 ERROR [p-759477796-118] - o.s.n.r.ContentPlex~ - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar": Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
Define following property in your pom
<deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl>
Change configuration of maven-deploy-plugin as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<configuration>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<url>${deployFileUrl}</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
</configuration>
<goals>
<goal>deploy-file</goal>
</goals>
</execution>
</executions>
</plugin>
Add following profile to set the deployFileUrl property with repository url
<profiles>
<profile>
<id>release-mode</id>
<properties>
<deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl>
</properties>
</profile>
</profiles>
Finally call this profile in maven-release-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-9</version>
<configuration>
<releaseProfiles>release-mode</releaseProfiles>
</configuration>
</plugin>
So the best clue actually turned out to be right in front of my eyes in the log. The only artifact I had thought was being produced by the POM I was working with was a .war, but you'll notice in the log that the artifact which Maven is attempting to deploy to the release is actually a .jar.
This was enough of a pointer (that someone on the Maven users mailing list pointed provided) to look for and eventually find that someone had included the following extra configuration for the deploy phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<url>${project.distributionManagement.repository.url}</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Notice that this is in fact directly referencing ${project.distributionManagement.repository.url}. Also, this configuration was somewhat misguided and should really have been accomplished via the attachClasses property of the war plugin.
Could it be because the artifact version does not have -SNAPSHOT suffix?

Resources