determine if artifact exists in a remote repo without downloading it - maven

This may be similar to: Maven: How to check if an artifact exists?
Except I don't want to determine the existence of the artifact from within a mojo.
I want to know if the artifact exists in my repo preferably just from the command line. (ie mvn some:plugin -Drepo... -Dgroup... -Dversion... -Dartifact... etc.
The reason I want to know this is this: We have a yum repo and we are migrating it to a Sonatype Nexus repo, which is a maven repo under the covers. I don't want to "mvn deploy" a huge rpm only to have it fail because it already exists in the repo. If it exists in the repo, I don't want to deploy it.
Any ideas how I can check if an artifact exists in a maven repo without having to download it first?

The Maven Wagon plugin can determine if an artifact exists if given a URL to a Maven repository:
You will have to build that URL beforehand using groupId, artifactId, etc.
mvn wagon:exist -Dwagon.url=http://repo1.maven.org/maven2/javax/servlet/jstl/1.2
when run within your project, will produce:
[INFO]
[INFO] --- wagon-maven-plugin:1.0-beta-4:exist (default-cli) # proj ---
[INFO] exists.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Related

Maven download Artifact form Nexus is endless

I have strange behavior with maven. During my build, the download of the json-smart metadata component (the only artifact that seems to be affected by this problem) loops without ever stopping.
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< fr.project:myProject >----------------
[INFO] Building Ned MyProject 1.8.2
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from nexus: http://mynexus/repository/maven-public/net/minidev/json-smart/maven-metadata.xml
If I pour central maven repo directly it's OK but if I use our Nexus, the problem is still there.
I check certificat, they are OK I check nexus log, there is nothing
about this download Maven Log in debug show nothing elses (just this
final command)
I have use -U and udpatePolicy command in maven setting but nothing (When maven says "resolution will not be reattempted until the update interval of MyRepo has elapsed", where is that interval specified?)
I have clean all json-smart artifact form maven-central repo of our
nexus and task a clean metadata but nothing(Remove artifacts from Nexus repository and how to force sonatype nexus 3 to recreate maven-metadata.xml for maven repository?)
I have no other ideas, has anyone as one ?
Apache Maven 3.6.3
Java version: 11.0.3, vendor: Oracle Corporation
Nexus : 3.6.0-02
We found the solution but no explication on the real problem.
metadata of our json-smart artefact were corrupted on our Nexus and block download from maven. I have delete all composant, invalidate cache of the repository and rebuilt the index and it's seem resolve the problem.

Purge artefacts with maven-dependency-plugin

I want to run mvn command to get rid of all artefacts under ~/.m2/repository/here/goes/my/groupid. In order to do so, I run:
mvn -pl my-module dependency:purge-local-repository -DresolutionFuzziness=groupId -Dinclude=<here-goes-my-groupid> -DactTransitively=false -DreResolve=false -Dverbose=true
This works fine, as long as the current version (3.0.0) of the current artefact (my-maven-plugin) is in the local repo.
If the current version (3.0.0) of the current artefact (my-maven-plugin) is not in the local repo (e.g. there is only an older version of this artefact in the local repo, say 2.9.0), nothing gets purged:
[INFO] --- maven-dependency-plugin:3.0.0:purge-local-repository (default-cli) # my-maven-plugin ---
Downloading: https://repo.maven.apache.org/maven2/here/goes/my/groupid/my-maven-plugin/3.0.0/my-maven-plugin-3.0.0.jar
[INFO] Unable to resolve all dependencies for : <here-goes-my-groupid>:my-maven-plugin:3.0.0. Falling back to non-transitive mode for initial artifact resolution.
[INFO] No artifacts included for purge for project: <here-goes-my-groupid>:my-maven-plugin:maven-plugin:3.0.0
I don't understand why maven-dependency-plugin tries to download anything from maven central. All it should do is to recursively drop a folder in local filesystem.
How can I enforce purging all artefact under given groupId, no matter if the current version of the current artefact is in the local repo or not?
include expects the groupId of the dependency being purged to be exactly same as that of the project.
The options resolutionFuzziness, actTransitively and reResolve apply only when the said groupId condition is satisfied.
I guess, this might be because the plugin developers want to prevent the accidental purging of artifacts that are out of project's group. It's my wild guess though.
Relax! manualInclude comes to the rescue. It can purge the artifacts irrespective of the project's groupId.
Try this:
mvn dependency:purge-local-repository -DmanualInclude=<group-id>:<artifact-id>
or this:
mvn dependency:purge-local-repository -DmanualIncludes=<group-id>:<artifact-id>
However, the difference is that unlike include it doesn't re-resolve the artifact after purge, no matter what value you give to reResolve.
This condition skips the re-resolve.

Keep maven artifact name on maven-install-plugin (default-install)

I try to include the git commit hash in the artifact name to distinguish between Snapshot-Versions in an CI scenario.
The git hash is successfully included in the target/ folder of my project, but in the last maven step it copies the artifact into my HOME/.m2/repositories folder and changes the name to ARTIFACTID-VERSION-mta.jar.
How can I keep the file name from the target/ folder that includes the commit hash?
I had a look at the maven-install-plugin, but couldn't find a "finalName" property or something like this.
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # projectname ---
[INFO] Installing PROJECTDIR/pom.xml to ~/.m2/repository/GroupIdDir/projectname/1.0.1/projectname-1.0.1.pom
[INFO] Installing PROJECTDIR/target/projectname-1.0.1-d054c42-mta.jar to ~/.m2/repository/GroupIdDir/projectname/1.0.1/projectname-1.0.1-mta.jar
I would like the last line to be
[INFO] Installing PROJECTDIR/target/projectname-1.0.1-d054c42-mta.jar to ~/.m2/repository/GroupIdDir/projectname/1.0.1/projectname-1.0.1-d054c42-mta.jar
Controlling maven final name of jar artifact
does not solve the problem because it modifies the output folder.
it is probrably because of repository layout.
Repository Layout Definition
This is the final layout for the repository available in Maven 2.x and
its related Ant tasks.
For primary artifacts:
/$groupId[0]/../${groupId[n]/$artifactId/$version/$artifactId-$version.$extension
For secondary artifacts:
/$groupId[0]/../$groupId[n]/$artifactId/$version/$artifactId-$version-$classifier.$extension
See https://cwiki.apache.org/confluence/display/MAVENOLD/Repository+Layout+-+Final

Maven deploy from parent project

I have maven parent project with several child projects. On deploy I want to execute some complex scp tasks. When i run mvn deploy i have error:
[INFO] Reactor Summary:
[INFO]
[INFO] Child project1 ............................... FAILURE [0.331s]
[INFO] Child project 2 .............................. SKIPPED
[INFO] Child project 3 .............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
(default-deploy) on project Parent: Deployment failed: repository element
was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
I read the question Deployment issue with Maven Plugin it says that i need to define repository in settings.xml. But i don't have any repository, all I want to do on deploy phase is execute script that copy files on server and do other work. And I want to execute this script only in parent project and scip this phase in child.
I've not worked with maven very much, so maybe i'm just missing some maven concept.
If you don't have a repository (meaning: deployment/project repository, not local that you must have), then don't run mvn deploy, but rather mvn install. Maven Release Plugin (bound to the deploy phase by default) is for installing your artifacts in your project repository, labelling it in the source control repository, stuff like that. Which means: you have to define repositories and source control connection in your main POM, and perhaps credentials for your repository access in settings.xml.
If you want to skip certain projects (included as <modules>, right?), I think your best option is to use profiles with different <modules> sections inside for every profile.

Jenkins (hudson) plugin development meet maven-enforcer-plugin:1.1-SNAPSHOT issue

I try to develop one jenkins (a.k.a hudson) plugin, and follow the Tutorial, and generated source code tree after mvn -cpu hpi:create command.
While when I do "mvn package", it reports error like
[INFO] Building Unnamed - com.example.jenkins:redmine2:hpi:1.0-SNAPSHOT
[INFO] task-segment: [clean]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.apache.maven.plugins:maven-enforcer-plugin
Reason: Error getting POM for 'org.apache.maven.plugins:maven-enforcer-plugin' from the repository: Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.
org.apache.maven.plugins:maven-enforcer-plugin:pom:1.1-SNAPSHOT
from the specified remote repositories:
nexus (http://maven.nexus.local:8888/nexus/content/groups/public)
for project org.apache.maven.plugins:maven-enforcer-plugin
From my nexus server, it has maven-enforcer-plugin:1.0 version only, but this dependence is generated from jenkins by default, anyone can help me to solve it ?
(How) Can I change to plugin-1.0 version.
what can I add in nexus server
I just have basic knowledge of maven.
I fixed it by myself by doing two things.
1. Added Apache snapshot from here into my nexus repo group besides those setting in Tutorial
2. It seems my local maven repo is messed up as well, so I can clean it up and reload from nexus.
And it still use maven-enforcer-plugin:pom:1.1-SNAPSHOT plugins.
Hope it helps you as well.

Resources