how to exclude artifact from deploy in specific profile - maven

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?

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?

Maven distributionManagement

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>

How to fetch artifacts from own repo using maven?

How do I create a simple project that fetches artifacts from my repo using maven? And where will these artifacts get saved to - my default maven repo?
I am using Apache Archiva.
Just simply start using a repository manager like Nexus and that's it. Please configure your settings.xml file according to the following:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>URL OF your ARCHIVA SERVER</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>
The artifacts which are being downloaded are first stored into the Archiva and of course on your hard drive $HOME/.m2/repository.
If you like to deploy artifact into archiva you need to configure the distributionManagement in your pom file similar like this:
<distributionManagement>
<repository>
<id>releases</id>
<name>Archiva RElease repo</name>
<url>http://URL OF YOUR ARCHIVA/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots<id>
<name>Archiva Snapshots repo</name>
<url>http://URL OF YOUR ARCHIVA/snapshots/</url>
</snapshotRepository>
...
</distributionManagement>
...
To test this you can use mvn deploy to see if the artiacts are being deployed to the snapshot repository. You can change the version of your test project into 1.0 and redo a mvn deploy which will try to deploy the artifacts into the release repository.

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