Maven: is there a simple command to test repository access? - maven

Some of my users have trouble accessing our local Nexus repository. Some of them are somewhat newbies in maven configuration. Sure they can test if everything is downloading fine running mvn install, but I'd like to help them to isolate their environment problems.
Is there a simple mvn command just to test if the repository access is correctly configured?

Use
mvn help:effective-settings

A simple
mvn clean
test the repository access.

I had a number of dependencies that failed to download from the Maven Central repository (apparently due to network throttling/flakiness). Running "mvn clean" just immediately returned with the same errors, obviously not attempting any more downloads. But its message said to rerun with "-x" option to see the full stack trace, so I ran:
mvn clean -x
This caused it to retry and download more. It took several tries to get all dependencies downloaded, but it did eventually run to completion. It didn't give me any stack traces, and I still don't know what was causing the failures (the repository was reachable the whole time).

Related

parallel build not working with release plugin

Maven -T not working with release plugin
I start to write as answer cause the comment area is too limited.
The mentioned point 2. must have failed with an error cause -T requires parameters (Missing argument for option: T`)
Furthermore the given call release:prepare release:perform clean install deploy is simply wrong.
Let us begin with some basics. A combination of install and deploy shows that there is a misunderstanding about the Maven life cycle.
So using install only makes sense if you want to install the artifacts only into your local repository ($HOME/.m2/repository) to be consumed by other project on the same machine which is usually not the case.
Using deploy (which includes install) is used to upload the created artifacts into a remote repository (like Nexus, Artifactory) which is in corporate environments the case.
Based on the output I can see that you are using extremely old plugin versions like maven-dependency-plugin:2.1: this version is ten years old. Furthermore I see the usage of a sources goal which is used to resolve sources of the dependencies where I would ask: Why do you need that?
The mentioned point 1:
mvn deploy -U -T 1C -DskipTests -Dmaven.install.skip=true
this shows that you have not understand the purpose of install and deploy phase cause the install phase is needed to install the artifacts and deploy phase will transfer them to the remote repository which means it does not make sense to skip the install part (I doubt that this will work). Furthermore using -U only would make sense if you have SNAPSHOT dependencies otherwise this is waste of time.
The usage of -DskipTests gives me the impression you seemed to have long running unit tests (or they might be integration tests instead?)...
To make a release with Maven you should go:
mvn release:prepare release:perform
Nothing else. Based on the supplemental parameters you are giving during a release it looks like your pom files seemed to be not in optimal state.
The given option -DcheckModificationExcludeList=pom.xml looks from my point of view like a problem cause usually you don't need that and furthermore during a release the pom.xml will be changed (the version) so from that point of view it does not make sense. The modification is to check if something not checked in before running a release..(The whole thing looks not concise to me).
Based on the error message you have given:
[ERROR] Failure executing javac, but could not parse the error:
I bet your maven-compiler-plugin version is very old? Which version do you use?
I recommend to use an up-to-date version of maven-release-plugin which is hopefully correctly configured in your pom file (which I can't tell you cause you haven't showed the full pom files).
Also I recommend to use a most recent version of Maven and check all plugins (using most recent versions) and in particular the configuration of the appropriate plugins if the configuration is correct and really needed and fulfills your needs.

maven: Go online after going offline for remote development

$ mvn dependency:go-offline
caches all the dependencies for offline/remote development. It is documented at https://maven.apache.org/plugins/maven-dependency-plugin/go-offline-mojo.html
But, how do we go back online again?
$ mvn dependency:go-online
is not a valid goal.
Thanks.
Check dependency:go-offline goal's documentation .
In the description it states:
Goal that resolves all project dependencies, including plugins and
reports and their dependencies.
Emphasis mine.
This goal just tells Maven to resolve everything this project is dependent on (dependencies, plugins, reports) in preparation for going offline. So it just fetches locally all required stuff and nothing more.
Offline mode is enabled only when you provide the -o flag on a appropriate command ex. mvn -o install and for the scope of this command only.
In the above command, if -o is specified, maven will not check online for updates of dependencies,plugins etc and will try to retrieve them from the local repository. That's why you have to execute the aforesaid goal of maven dependency plugin before, in order everything to be available for offline mode.

lein tries to download artifact even though it exists locally

lein run results in the following error:
Could not find artifact foo:common:jar:10.11.0 in central (https://repo1.maven.org/maven2/)
Could not find artifact foo:common:jar:10.11.0 in clojars (https://clojars.org/repo/)
However, on my computer, the file ~/.m2/repository/foo/common/10.11.0/common-10.11.0.jar exists. It seems like lein is trying to download the file from central and clojars, even though it already exists on my computer.
This particular jar does not exist in the maven central or clojars, it exists in a private repository, that I only have access to when I'm on a certain network. I'm not on that network right now, so it would really help if lein did not try to download a file that already exists on my computer.
Does anyone know how to fix this?
Update
I got the information that you can run lein in offline mode using lein -o .... This resulted in the following error though:
The repository system is offline but the artifact foo:common:jar:10.11.0 is not available in the local repository.
lein is likely checking for updates, which it won't be able to access while you're off that network, as you had diagnosed.
Run lein with its -o option for offline mode, and it should skip the remote repo checks.
The above sounds good. Also see the following, where you may want to bypass the whole maven jar mechanism and put the jar in ./resources (at least temorarily):
leiningen - how to add dependencies for local jars?
Note carefully the required format of the resource strings!
(defproject test-project "0.1.0-SNAPSHOT"
:description "Blah blah blah"
...
:resource-paths ["resources/Siebel.jar" "resources/SiebelJI_enu.jar"])
See also the option for doing a local maven install in another answer in that link:
mvn deploy:deploy-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -Durl=file:maven_repository

Maven Build gets Failed saying Could not assemble p2 repository: Mirroring failed: No repository found at

I have a maven build for building an eclipse plugin which gets hung sporadically during the execution of
--- tycho-p2-repository-plugin:1.1.0:assemble-repository (default-assemble-repository) # com.sample.product ---
Otherwise the build will get failed saying the following error.
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-p2-repository-plugin:1.1.0:assemble-repository (default-assemble-repository) on project p2:Could not assemble p2 repository: Mirroring failed: No repository found at file:/C:/Users/obuli/.m2/repository/.
I am using the following maven goals and options
clean deploy -Dtycho.localArtifacts=ignore
I have searched for this issue and landed on this Bug , It says there was a bug in tycho 0.26.0 But I am currently using Tycho version 1.1.0
Since the issue is very sporadic I could not able to identify the root cause. Please let me what I am missing here.
I intermittently had this problem as well. After running mvn clean and mvn deploy separately once, mvn clean deploy started working as well.
Now I don't seem to be able to recreate the original issue, even using git clean -xfd and deleting all snapshots from the local and remote repository.
I can only guess that there were some leftover files from earlier builds which were not cleaned by mvn clean deploy but by mvn clean, and these leftover files must have broken the build.

execute command mvn clean install failed when integrate with Jenkins

I try to build Jenkins with maven project and in goal I defined: clean install.
But it failed with the below reason:
I try to execute the command mvn clean install in command line but it works fine even with eclipse IDE.
I also check the network and see I can connect successfully.
Any solution in this case.
By default, Jenkins can't access the internet if you are under Proxy. So please configure proxy in jenkins. Here I am attaching a link to configure the jenkins. Hope this helps. If anything comes up, please comment below.

Resources