Create an hermetic Maven build - java

I'm preparing a workshop where they may be no Internet connection. Because of that, I'd like to provide every dependency/plugin of the project, so attendees can work on it, completely offline.
I've got a basic Maven project with some dependencies and two plugins.
First, I created an alternate local repository:
mvn -Dmaven.repo.local=dependencies dependency:go-offline
Then, I expected the following command to run fine, but it doesn't! And I some mentioned missing plugins are not available in maven central or within the maven distribution:
mvn -o -Dmaven.repo.local=dependencies package
This fail with the following error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project XXX: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-profile:jar:2.0.6, org.apache.maven:maven-repository-metadata:jar:2.0.6, org.apache.maven:maven-plugin-registry:jar:2.0.6, classworlds:classworlds:jar:1.1-alpha-2: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven:maven-profile:jar:2.0.6 has not been downloaded from it before.
Any idea how to get these missing bits while creating an alternate local repo? Thanks in advance!

Based on this issue in the plugin's Jira this problem is still not resolved.
The best work around so far is to package the project online once, using the custom repository.
mvn -Dmaven.repo.local=dependencies dependency:go-offline
then
mvn -Dmaven.repo.local=dependencies package
and finally
mvn -Dmaven.repo.local=dependencies -o package
If your workshop go farther than deploy, you should check that next goals run fine offline too!

can you declare pluginManagement for every plugin that is used by your packaging? That should enable downloading when dependency:go-offline is called.
(in addition, this will improve stability for your build, since you'll be sure that changing Maven version won't change plugins versions)
Can you confirm this works?
(now, I have ideas to improve this, but won't be available before a few months at least...)

The documentation seems to suggest that you need to run:
mvn dependency:resolve-plugins
Before go-offline
Could you try it?
See: https://people.apache.org/~aramirez/maven-dependency-plugin/go-offline-mojo.html

Related

while doing maven clean install i am getting this kind of error in eclipse smart home

while doing maven clean install i am getting this kind of error in eclipse smart home
" Failed to execute goal on project eclipsesmarthome-incubation: Could not resolve dependencies for project org.eclipse.smarthome:eclipsesmarthome-incubation:pom:0.10.0-SNAPSHOT: Could not find artifact org.eclipse.smarthome.products:org.eclipse.smarthome.repo:zip:0.10.0-SNAPSHOT -> [Help 1]"
can any one help me out
The artifact
org.eclipse.smarthome.products:org.eclipse.smarthome.repo:zip:0.10.0-SNAPSHOT
is not available. This could have several reasons:
if this artifact is supposed to come from a Maven repository on the internet, make sure that this Maven repository is added to the setttings.xml
if you are behind a proxy/firewall, make sure your Maven can go through it.
if you just downloaded the artifact, you need to add it to your local repository with the help of the Maven install plugin.

MVN install, cannot find artifact in local repository

I did mvn install and get this error message
Failed to execute goal on project core: Could not resolve dependencies for project test:core:jar:2.0.1-SNAPSHOT: Could not find artifact lib-net:lib-net:jar:1.0.8 in central (http://repo.maven.apache.org/maven2)
this dependency is a Project of mine, which is available in the local repository ~/.m2
so I tried mvn install -o to force maven to use my local repository, and I get this
Failed to execute goal on project core: Could not resolve dependencies for project test:core:jar:2.0.1-SNAPSHOT: The repository system is offline but the artifact lib-net:lib-net:jar:1.0.8 is not available in the local repository.
I tried to delete my local repository and install everything again, but it doesn't solve my problem!
Any sugestions?
The problem is with maven version. I had the same issue on my Jenkins machine. I followed these steps and it resolved my issue:
Delete the specific older libraries in ~/.m2/
Change the version of maven to apache-maven-3.5.0
Re-run the maven goals
Think I know way how to do it properly
Download sources of your library locally
Go to ~/.m2/ and search for your lib
Delete it from here
perform "mvn clean install" for your library
search for your lib in ~/.m2/
try to "mvn clean install" on your main project
... ?
Profit
If it will no work, check that you use correct artifact id and group id.

How to resolve failure of dependency error? [duplicate]

I imported my already working project on another computer and it started to download dependencies.
Apparently my internet connection crashed and now I get the following:
>Build errors for comics; org.apache.maven.lifecycle.LifecycleExecutionException:
Failed to execute goal on project comicsTest: Could not resolve dependencies for project comicsTest:comicsTest:war:0.0.1-SNAPSHOT:
The following artifacts could not be resolved:
org.springframework:spring-context:jar:3.0.5.RELEASE,
org.hibernate:hibernate-entitymanager:jar:3.6.0.Final,
org.hibernate:hibernate-core:jar:3.6.0.Final,
org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final,
org.aspectj:aspectjweaver:jar:1.6.8,
commons-lang:commons-lang:jar:2.5,
>mysql:mysql-connector-java:jar:5.1.13: Failure to transfer org.springframework:spring-context:jar:3.0.5.RELEASE from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.
>Original error: Could not transfer artifact org.springframework:spring-context:jar:3.0.5.RELEASE from central (http://repo1.maven.org/maven2): No response received after 60000
How do I force maven to update?
mvn clean install -U
-U means force update of snapshot dependencies.
Release dependencies will be updated this way if they have never been previously successfully downloaded. ref: https://stackoverflow.com/a/29020990/32453
If your local repository is somehow mucked up for release jars as opposed to snapshots (-U and --update-snapshots only update snapshots), you can purge the local repo using the following:
mvn dependency:purge-local-repository
You probably then want to clean and install again:
mvn dependency:purge-local-repository clean install
Lots more info available at https://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html
-U seems to force update of all SNAPSHOT dependencies.
If you want to update a single dependency without clean or -U you could just remove it from your local repo and then build.
The example below if for updating slf4j-api 1.7.1-SNAPSHOT:
rm -rf ~/.m2/repository/org/slf4j/slf4j-api/1.7.1-SNAPSHOT
mvn compile
All the answers here didn't work for me. I used the hammer method:
find ~/.m2/ -name "*.lastUpdated" | xargs rm
That fixed the problem :-)
You can do effectively from Eclipse IDE. Of course if you are using it.
Project_Name->Maven->Update Project Configuration->Force Update of Snapshots/Releases
Just in case someone wants only update project's snapshot dependencies and doesn't want to install artifact:
mvn dependency:resolve -U
Don't forget to reimport dependencies in your IDE. In IDEA you need to right click on pom file and choose Maven -> Reimport
If you're unsure what is inside your local repository, I recommend to fire a build with the option:
-Dmaven.repo.local=localrepo
That way you'll ensure to build in a cleanroom environment.
In my case first I did was:
mvn clean install -U
Still it was showing same error then I closed project and again reopened it. Finally worked.
If you are using eclipse IDE then :
Select Project.
Press alt+F5, window for Update Maven Project will pop up.
Check - Force Update of Snapshots/releases and click OK.
If Using Intellij IDE
go to settings/Maven
check Always update snapshots
I used the IntelliJ IDE and I had a similar problem and to solve I clicked in "Generate Sources and Update Folders for All Projects" in Maven tab.
Previous versions of maven did not force the check for missing releases when used -U with mvn clean install, only the snapshots, though newer version supports this.
For someone still struggling with previous version, following can be helpful-
On Windows:
cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i
On Linux:
find ~/.m2 -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;
Whenever maven can't download dependencies for any reason (connectivity/not exists etc), it will add the ".error=Could not transfer artifact" in dependency-name.lastUpdate file in respective folder under $home/.m2 directory. Removing these files will force maven to try fetching the dependencies again.
mvn clean install -e -U -Dmaven.test.skip=true
-e Detailed exception
-U forced update
-DskipTests does not execute test cases, but compiles test case classes to generate corresponding class files under target/test classes.
-Dmaven.test.skip=true, do not execute test cases or compile test case classes.Using maven. test. skip not only skips running unit tests, but also skips compiling test code.
A small suggestion. If you use the IntelliJ Idea compiler, it is recommended to clean the cache
I've got the error in an other context.
So my solution might be useful to others who stumple upon the question:
The problem:
I've copied the local repository to another computer, which has no connection to a special repository.
So maven tried to check the artifacts against the invalid repository.
My solution:
Remove the _maven.repositories files.
You need to check your settings.xml file under <maven_home>/conf directory.
This is one of the most annoying things about Maven. For me the following happens: If I add a dependency requesting more dependencies and more and more but have a slow connection, it seams to stop while downloading and timing out. While timing out all dependencies not yet fetched are marked with place holders in the .m2 cache and Maven will not (never) pick it up unless I remove the place holder entry from the cache (as other stated) by removing it.
So as far as I see it, Maven or more precise the Eclipse Maven plugin has a bug regarding this. Someone should report this.
It's important to add that the main difference of running mvn with -U and without -U is that -U will override your local SNAPSHOT jars with remote SNAPSHOT jars.
Local SNAPSHOT jars created from local mvn install in cases where you have other modules of your proj that generate jars.
For fixing this issue from Eclipse:
1) Add below dependency in Maven pom.xml and save the pom.xml file.
<!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
</dependency>
2) Go to project >> Maven >> Update Project
select the project and click OK.
3) Optional step, if it's not resolved till step 2 then do below step after doing step-1
Go to project >> Maven >> Update Project >> check in the checkbox 'Force Update of Snapshots/Releases'
select the project and click OK.
-U is used to force update maven Repo.
Use
mvn -U clean install
I've got the same error with android-maps-utils dependency. Using aar type package in dependency section solve my problem.
By default type is jar so It might be checked what type of dependency in repository is downloaded.
I tried all the answers here but nothing seemed to work. Restarted my computer first then ran mvn clean install -U. That solved my problem.
What maven does is, it downloads all your project's dependencies into your local repo (.m2 folder). Because of the internet causing issues with your local repo, you project is facing problems. I am not sure if this will surely help you or not but you can try deleting all the files within the repository folder inside the .m2 folder. Since there would be nothing in the local repo, maven would be forced to download the dependencies again, thus forcing an update.
Generally, the .m2 folder is located at c:users:[username]:.m2
after using mvn clean install -U run as maven test also and after that update your project using maven-update project
this works in my case
I had this problem for a different reason. I went to the maven repository https://mvnrepository.com looking for the latest version of spring core, which at the time was 5.0.0.M3/ The repository showed me this entry for my pom.xml:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.0.M3</version>
</dependency>
Naive fool that I am, I assumed that the comment was telling me that the jar is located in the default repository.
However, after a lot of head-banging, I saw a note just below the xml saying "Note: this artifact it located at Alfresco Public repository (https://artifacts.alfresco.com/nexus/content/repositories/public/)"
So the comment in the XML is completely misleading. The jar is located in another archive, which was why Maven couldn't find it!
We can force to get latest update of release and snapshot repository with below command :
mvn --update-snapshots clean install
I had the same error and running mvn install -U and then running mvn install worked for me.
mvn clean install -U doesn't work. However mvn -U clean followed by mvn clean install does.

m2eclipse will not download any dependencies

I was hoping someone might be able to help.
On a brand new windows machine. I've downloaded and installed java jdk before downloading and running the latest version of eclipse (indigo).
From there I have installed the maven integration plugin from the marketplace and created a new maven projected.
The project has a ton of errors mainly to do with missing dependencies or life cycle management.
When I do maven-clean I get the following error message:
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.4.1 from/to central (http://repo1.maven.org/maven2): Invalid argument: getsockname to http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom -> [Help 1]
I am not behind a firewall and I do not use a proxy. My maven settings.xml is completely default as is my maven project. No classes added, nothing added to the pom.
Can anyone help?
All the best.
p.s here are the errors shown in the pom:
1:
CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2: ArtifactResolutionException: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:2.3.2 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:2.3.2 from/to central (http://repo1.maven.org/maven2): Invalid argument: getsockname to http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.pom
2:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (execution: default-testCompile, phase: test-compile)
3:
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (execution: default-compile, phase: compile)
4:
Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.4.3 from/to central (http://repo1.maven.org/maven2): Invalid argument: getsockname to http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.4.3/maven-resources-plugin-2.4.3.pom
Furthermore i recommend to test the configuration etc. first with command line client of Maven (Maven 3.0.X) and not within Eclipse.
The 1./4. shows that you have tried to download some artifact which has failed for whatever reasons. The simple solution for that is to delete the local repository and retry the build. But i recommend to do that first on command line to check if everything is fine.
The 2./3. are indications that the project you are trying to compile does not contain a correct plugin coverage for m2e which can be read in the docs how to solve that.
Problem:
You are missing an artefact in Your maven repository.
How to verify:
If You will browse Your repository You will find out that under .m2/repository/org/apache/maven/plugins/maven-clean-plugin/2.4.1/ artefact will have lastUpdated suffix - maven attempted to download this artefact but failed.
How to solve:
Just add an appropriate artefact into Your maven repository:) There are several ways how to do that but the simplest one will be dropping the folder with the missing artefact. Add since You can build Your project from the CMD just add missing artefact as a dependency into Your project. Build the project from the CMD.
Add dependency is not working through eclipse IDE(JUNO 4.2). Fixed the issue by manually adding dependencies with the below command on command prompt
go to the location where your pom.xml is located
mvn install
once you see status BUILD success from now onwards we can proceed with IDE.
Clearly this is an issue of proxy. Either use VPN or edit procy setting in setting.xml. I searched lot about this error. Finally, I used VPN(Virtual private network ) to disable the proxy and was able to use cetral repository of Maven.
IF you dont want to USE VPN just change Settings.xml host address with proxy address of ur company(which is available in IE->tools->connection->LAN settings->advanced->http. )
This is a proxy problem:
add your proxy config in your setting.xml
remove .m2 folder from your home directory
run any maven command in interactive mode from command line, for example try to create a project
mvn archetype: generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.mycompany.app -DartifactId=my-webapp
that's all
I had the same problem. It was because I configured the repository in the settings.xml of my Maven Installation. But this in not used by Eclipse as it comes with its own Maven implementation. You need to configure the repositories (mirror section) in the settings.xml in your profile (.m2/settings.xml).

What is needed in order to run the JTestR samples? (or using JTestR at all)

I've spent some time trying to use JTestR. I haven't succeeded in any way :\
Take this sample for instance:
https://github.com/olabini/jtestr/tree/master/examples/simple_maven_project
Running 'mvn test' here gives me:
[ERROR] Plugin
org.jtestr:jtestr:0.7-SNAPSHOT or one
of its dependencies could not be
resolved: Failed to read artifact
descriptor for
org.jtestr:jtestr:jar:0.7-SNAPSHOT:
Could not find artifact
org.jtestr:jtestr:pom:0.7-SNAPSHOT
I'm also unable to build the current master branch from the github repository.
I then tried downloading the v0.6 dist and following the Getting Started section, but with errors:
[ERROR] Failed to execute goal
org.jtestr:jtestr:0.6:test (default)
on project jtestr: Execution default
of goal org.jtestr:jtestr:0.6:test
failed: Plugin org.jtestr:jtestr:0.6
or one of its dependencies could not
be resolved: Could not find artifact
org.jtestr:jruby-complete:jar:r1c672b495cfd204421f4a7aed17f6135e730a3b2
I suspect that this is because I've put my jtestr jar file in the wrong place. Where should it be?
now this is because for some reason maven could not resolve one of JTestR's dependency - a custom packaged complete jruby jar - there's a simple solution although :
download the jar from http://dist.codehaus.org/jtestr/
http://dist.codehaus.org/jtestr/jruby-complete-r1c672b495cfd204421f4a7aed17f6135e730a3b2.jar
then hand install it to Your local maven repository :
mvn install:install-file -DgroupId=org.jtestr -DartifactId=jruby-complete -Dpackaging=jar -Dversion=r1c672b495cfd204421f4a7aed17f6135e730a3b2 -Dfile=[PATH_TO_DOWNLOADED.jar]

Categories

Resources