Maven distributionManagement - maven

I develop a web application, and I am about to deploy in the server artifactory anonymously. I have distinguished the snapshot and release repositories with the corresponding artifactory url in the distributionManagement of my parent POM. The problem is that the deployment is always done in release and not in snapshot. Help me make the deposit in release and snapshot.
Here is my distributionManagement:
<distributionManagement>
<repository>
<id>My release</id>
<name>Release</name>
<uniqueVersion>true</uniqueVersion>
<layout>default</layout>
<url>repo/artifacotry/release</url>
</repository>
<snapshotRepository>
<id>My snapshot</id>
<name>Snapshot</name>
<uniqueVersion>false</uniqueVersion>
<layout>default</layout>
<url>repo/artifacotry/snapshot</url>
</snapshotRepository>
</distributionManagement>

Related

Maven project use multiple GitLab Package Registry

I am trying to setup 2 GitLab projects (project a & project b) as the remote maven repository for my other project (project c) using GitLab Maven Package Registry.
Now I have 2 GitLab Maven Package Registry
project A -> id : 112233
project B -> id : 445566
So, now I need to set the registry setup in my project C pom.xml file
How I can do that, because we can't have multiple in our pom.xml file
<!--registry setup for project a-->
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<!--registry setup for project b-->
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</snapshotRepository>
</distributionManagement>
If project A and B sit in the same group, then you shall use the group-level Maven endpoint in project C's pom.xml:
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.example.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
</repository>
</repositories>
Else, I guess you should be able to specify one repository for each:
<repositories>
<repository>
<id>gitlab-maven-a</id>
<url>https://gitlab.com/api/v4/projects/112233/packages/maven</url>
</repository>
<repository>
<id>gitlab-maven-b</id>
<url>https://gitlab.com/api/v4/projects/445566/packages/maven</url>
</repository>
</repositories>
/!\ Don't forget to set your Maven authentication credentials in your settings.xml file in either case (unless your project has public visibility).
Prefer using the CI_JOB_TOKEN.

Artifactory OSS throwing 405 Exception when running maven release:perform

artifactory-oss-6.7.2 is throwing a 405 status code exception when running maven release:perform
Created a settings.xml from artifactory "generate settings.xml" on repo. All repos are virtual repos. Added distributionManagement to my project pom file to use the ids for snapshots and releases from settings.xml.
settings.xml:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://localhost:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://localhost:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
myproject/pom.xml:
<distributionManagement>
<repository>
<id>central</id>
<name>Artifactory Release Repo</name>
<url>http://localhost:8081/artifactory/libs-release</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Artifactory Snapshot Repo</name>
<url>http://localhost:8081/artifactory/libs-snapshot</url>
</snapshotRepository>
</distributionManagement>
run mvn release:perform output:
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project model: Failed to deploy artifacts: Could not transfer artifact com.test:model:jar:0.1.0 from/to central (http://localhost:8081/artifactory/libs-release): Failed to transfer file http://localhost:8081/artifactory/libs-release/com/srcrea/model/0.1.0/model-0.1.0.jar with status code 405 -> [Help 1]
So I followed something I found here -> http://forums.jfrog.org/Error-Code-405-with-mvn-deploy-td7174367.html
And updated DistributionManagement of the pom.xml
<distributionManagement>
<repository>
<id>central</id>
<name>Artifactory Release Repo</name>
<url>http://localhost:8081/artifactory/88888</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Artifactory Snapshot Repo</name>
<url>http://localhost:8081/artifactory/88888</url>
</snapshotRepository>
</distributionManagement>
Re-Run and now I see it:
But what is not clear is in order to generate settings.xml you need to associate virtual repos to a local repo. Then generate settings off that and use the distributionManagement configuration to point back to the local repo. What is the point of the virtual repo?

Retrieving dependencies from maven repository

So for my maven project I require jar dependencies that are available in public repositories and also jar dependencies that are on our company internal repository.
How do I configure my pom.xml so that I will retrieve the dependencies from public repositories and our company internal repository without synchronizing and uploading the stuff from public repos to the company internal repository.
In your settings.xml, which is usually in HOME_DIR/.m2 you need to add the company repository, maven central is included by default.
In the example below it will look for your artifact in each repo in order, starting with maven central.
<profile>
<id>extras</id>
<repositories>
<repository>
<id>release</id>
<name>libs-release</name>
<url>http://internal.corp:8091/artifactory/libs-release</url>
</repository>
<repository>
<id>snapshot</id>
<name>libs-snapshot</name>
<url>http://internal.corp:8091/artifactory/libs-snapshot-local</url>
</repository>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
<repository>
<id>spring-milestone</id>
<name>Spring Maven MILESTONE Repository</name>
<url>http://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
</profile>
I would also say that I set up our corporate repository so that is has a virtual repository to maven central. This means as people use artifacts they will be stored in the company repository. This is normal practice.

how to exclude artifact from deploy in specific profile

in our pom file we have a special profile that allow us to deploy artifacts to both our internal maven repo as well as external one which locate on google cloud.
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>nexus</id>
<name>Internal Releases</name>
<url>http://internal_instance_ip/nexus/content/repositories/releases</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>nexus-snapshots</id>
<name>Internal Snapshots</name>
<url>http://internal_instance_ip/nexus/content/repositories/snapshots</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
<profiles>
<profile>
<id>gce</id>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>nexus-gce</id>
<name>External Releases</name>
<url>https://gce_instance_ip/content/repositories/releases</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>nexus-snapshots-gce</id>
<name>External Snapshots</name>
<url>https://gce_instance_ip/content/repositories/snapshots</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
when I tried to deploy the project, it complained :
Return code is: 413, ReasonPhrase: Request Entity Too Large.
the project has lots of modules, the one that cause trouble doesn't need to be deployed to google cloud. How can i exclude that module from being deployed to the google cloud repo but still deployed to the internal repo?
You can exclude the module by passing the following argument on the command line:
--projects '!module-to-exclude'
From mvn --help:
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
See also How to exclude a module from a Maven reactor build?

How to configure maven project to deploy both snapshot and releases to Nexus?

How to configure maven project to deploy both snapshot and releases to Nexus?
<distributionManagement>
<repository>
<id>InternalReleases</id>
<name>Internal Releases</name>
<url>http://192.168.16.232:8081/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>InternalSnapshots</id>
<name>Internal Snapshots</name>
<url>http://192.168.16.232:8081/nexus/content/repositories/snapshots/</url>
</repository>
</distributionManagement>
This configuration creates error in Eclipse 3.8 with m2e 1.2
Project build error: Non-parseable POM D:\Workspaces\W\Parent\pom.xml: Duplicated tag: 'repository' (position: START_TAG
seen ...
I want the artifact deployed to the InternalSnapshots repository when the pom's version is suffixed with -SNAPSHOT and deployed to the InternalReleases repository when it is RELEASE. This should happen using the same pom.xml file and executing the same mvn deploy command.
You need to distinguish between the releases and snapshots repository. <distributionManagement> only allows one <repository> and one <snapshotRepository> child.
http://maven.apache.org/pom.html#Distribution_Management
Example of pom.xml configuration
<!-- http://maven.apache.org/pom.html#Distribution_Management -->
<distributionManagement>
<snapshotRepository>
<id>InternalSnapshots</id>
<name>Internal Snapshots</name>
<url>http://192.168.16.232:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>InternalReleases</id>
<name>Internal Releases</name>
<url>http://192.168.16.232:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
Snippets for .m2/settings.xml for default Nexus installation
<server>
<id>thirdparty</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>InternalReleases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>InternalSnapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
You can do both.
Add the maven-release-plugin 2.5.3
Run the following:
mvn deploy clean:release release:prepare release:perform

Resources