Uploading sources to nexus makes snapshot dependencies unavailable to maven - java

When we do mvn install deploy to a repository ${repository-jars} these dependencies can be used by others as intended.
When we afterwards upload sources to another repository ${repository-sources} the dependencies are no longer resolved correctly.
mvn deploy:deploy-file
-DgroupId=foo
-DartifactId=bar
-Dversion=1.0-SNAPSHOT
-Dfile=target/bar-sources.jar
-Dpackaging=jar
-Durl=${url}
-Dclassifier=sources
-DrepositoryId=${repository-sources}
Everything looks correct in nexus and both repositories are available in a regular Repository Group.
The hypothesis is that maven tries to use the latest uploaded artifact and ends up downloading the sources jar instead somehow ignoring the classes modifier. This is verified by first uploading sources and then do a maven deploy where it works as intended.
What is the correct way that allows us to upload sources in a separate job that runs after a deploy?

In examination, Maven is creating two different snapshots, and when you attempt to get latest, it's getting the newest one (which is sources) from the Group you've setup.
What you might actually try is putting them in the same repo, and separate them using Content Selectors. This is our newer version of Repo Targets from Nexus Repository 2.

Related

Pre-populate local Maven cache with specific dependencies

It looks like mvn install:install-file is for downloading a jar to a specific location.
I just want to manually download some publicly accessible dependencies to my local Maven cache (specifically the help and versions plugin). It doesn't have to be specific versions, just the latest versions is fine
I want Maven to install them just like it would with the install goal but just execute this from command line without a pom. Is this possible?
If you don't want create a pom.xml then you can use download-maven-plugin's artifact goal as shown in the below example.
You need pass groupId, artifactId and version. It
can't download the file if any one of these 3 are missing or not
matching with central repo. If you don't want to download pom file, you can ignore the second line.
Example:
mvn com.googlecode.maven-download-plugin:download-maven-plugin:1.4.2:artifact -DgroupId=log4j -DartifactId=log4j -Dversion=1.2.4 -Dtype=jar -DoutputDirectory=C:\Temp
mvn com.googlecode.maven-download-plugin:download-maven-plugin:1.4.2:artifact -DgroupId=log4j -DartifactId=log4j -Dversion=1.2.4 -Dtype=pom -DoutputDirectory=C:\Temp
This will download both JAR and POM files for log4j:log4j:1.2.4 from central repository to your local repository and also copies the files to C:\Temp folder. Once you are done downloading all the files, you can delete the Temp folder.

Building a Maven project offline

I am trying to install OreKit (an orbital mechanics toolkit) to validate some code i've written. Orekit is a maven project and thus it tries to download all its dependencies from the maven repo.
Unfortunately my company has pretty strict internet security measures and the maven repo is not whitelisted. The only way to access non-whitelisted websites is through a secure browser (tightGate) which is basically a video-feed of the browser running on a server. Files downloaded in this browser can then be transfered to my computer using a separate program.
This of course means that the build fails. I have been trying to download all the dependencies manually and put them in the local repository.
example:
eclipse error: "Missing artifact junit:junit:jar:4.12"
I downloaded the corresponding jar and pom files (junit-4.12.jar and junit-4.12.pom) and put them into my local repository (C:/Users//.m2/repository/junit/junit/4.12/)
I did this for every error eclipse reported but nothing changes and the same errors are still there.
Am i doing something wrong here? Is it even possible to build a project this way or should i just give up already?
In principle, this could work, but it would be easier to use mvn install:install-file for the separate jars.
Be aware that the number of artifacts that Maven usually requires is > 100.
We also have strict regulations, but managed to get an extra server with a Nexus that proxies MavenCentral, so we can reach the artifacts through there.
to put jar file in your local maven repository, you must install it.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
get more info from https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Pushing local maven repos to server

I am setting up a maven repository for my workplace. The main reason for setting up a new private repository is that, our original nexus repo is hidden behind a VPN network. So anyone who wished to pull the dependencies. He needs to have a VPN connection in the working machine. Goal is to make the VPN secured artefacts under the newly created repo to make it available for CI pipeline.
Right now I am doing it as below, listing all the dependencies using following command:
mvn -Dmdep.copyPom=true dependency:copy-dependencies
Which send all the jars under target/dependency.
And then I using the following maven command:
mvn deploy:deploy-file
Which pushes all the dependencies in my newly created nexus, issue is that during setting deploy-file command I am passing a group id which is a generic one. And all the jars are pushed under that groupid. Which is different than my local name namespace/groupid, as different packages are under different group id and pushing all of them under a same group id makes them unusable as it messes with the namespace.
I am new to maven, and the approach I took feels like a hack. Can I use maven native functionality to solve the problem? What would be the standard way to solve the issue?
Nexus has a concept of proxy repositories , for the open source dependencies, you can create proxy repository to mirror the maven central repo and provide in the proxy information is maven settings and run a mvn install, during the resource generation phase of maven the nexus will automatically pull artifacts from the central repo and cache them in your proxy repository for future use.

What does it mean in Maven when it says the following artifacts could not be resolved although they are in Maven cache?

I get the following error:
The following artifacts could not be resolved: com.sun.jdmk:jmxtools:jar:1.2.1, com.sun.jmx:jmxri:jar:1.2.1: Failure to find com.sun.jdmk:jmxtools:jar:1.2.1 in https://artifactory.corp.adobe.com/artifactory/maven-identity-snapshot was cached in the local repository, resolution will not be reattempted until the update interval of artifactory-snapshot
However, both jars are in the Maven cache (.m2 folder) on my machine. I mean files named: jmxri-1.2.1.jar and jmxtools-1.2.1.jar. They are respectively in the folders com/sun/jmdk/jmxtools/1.2.1/ and com/sun/jmx/jmxri/1.2.1
EDIT: When I try the -o switch on Maven to force it to use the local jars, it says the artifact has not been downloaded before. Which is probably true since indeed the artifact is not in the repo but was copied from some other place to my Maven cache -- is it possible to force Maven to use the jars? The -o switch does not seem to force this and Maven seems to be able to detect that the artifact was not downloaded.
Try to delete corresponding artifact folders in maven local repo and rerun or just rerun using -U flag.
Which is probably true since indeed the artifact is not in the repo but was copied from some other place to my Maven cache
Manually copying jars is not the correct way to put artifacts into maven local repo. You should use mvn install:install-file instead. More details here: Guide to installing 3rd party JARs
The dependency on those jars is usually a consequence of a bug in the pom.xml for log4j 1.2.15.
Update to 1.2.16 or 1.2.17 and you will not need these jars any longer.
These particular artefacts date back to a time when Sun licensing did not permit the hosting of the actual jars in a public maven repository.
You were required to accept licence conditions, download them yourself and then manually install either into your local repo (using mvn install:install-file) or into your corporate repository manager (typically using a UI that it provides or mvn deploy:deploy-file).

Sharing JARS with Maven Nexus Server... Only seeing update on workstation with common code

I am trying to setup a Maven Nexus Server for my firm to share common JARs that we build inhouse. I use my workstation (call it workstation 1) to build the common JAR and I then do a mvn deploy to deploy it to the Nexus Maven Server. Then I add it in the dependencies in the pom.xml of the project that needs it and I do my mvn package and everything is great.
Now if I change the common code and I run mvn deploy with the same version number and then rerun the mvn package on the second project, it will see the changes and everything is great.
Now lets move to workstation2. If I do a mvn package on the project that needs the common code everything is fine. But if the common code changes and I rerun the mvn package command it looks like it's going to my local repository on the workstation and using that version, not the new version in Nexus!
So my questions are the following...
Does mvn deploy save a copy in the local repository before the nexus repository?
How do I make the project check the nexus repository for the most up-to-date file before the local repository on the workstation?
The code is a accept SNAPSHOT so I would like it to be updated each time the user try to access it.
1) maven consult the local repository and only for a miss it aks the online repository (nexus)
2) I do not know
Anyway: (Except for SNAPSHOTS) you should not modifiy a released artefact without updating its version too!
You can run mvn -U package. With -U Maven will always check the repositories (in your case Nexus) for newer SNAPSHOT versions of your dependencies.
You can also add a configuration to your settings.xml to look always for new versions of dependencies. See the Settings reference, the configuration is named <updatePolicy>always</updatePolicy>
I got it.. I had to add always to the snapshot settings in my settings.xml

Categories