Maven Could not calculate build plan:Failure to transfer org.apache.maven.plugins - maven

When ever I try to update Maven dependencies I get an error like - Could not calculate build plan:null. At first I used to get the error like
Could not calculate build plan: Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 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-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2): ConnectException
But, when I have made changes to settings.xml file and added repository and plugin repository in settings.xml like
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</repository>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
</pluginRepository>
The previous error was removed, but now I get the following error: Could not calculate build plan:null
how to get rid of this error!! and also how to get rid of this warning
Classpath entry org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result. I tried to quick fix it, but whenever I reopen the project it again appears back. Any help would be appreciated.

I was able to solve this issue by enabling the proxy in settings.xml file located at config. At first tried different solutions by adding repository and pluginRepository in settings.xml file as mentioned in above question. But the actual problem was with the proxy configuration. I have tried the solution given by #akb at maven in 5 min not working. And the solution that worked out for me was Solution #1 as my organization's proxy setup was not auto-configured. Just included following data in settings.xml and do mvn clean, and update dependencies it worked.
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>webproxy</host>
<port>8080</port>
<username>proxyuser</username>
<password>proxypass</password>
</proxy>
</proxies>

Related

Spring Asciidoctor Extensions not in correct repo?

Good afternoon guys,
I've been trying to get spring-asciidoctor-extensions to work with my documentation but for some reason maven can't find the dependency.
The error i got after my build attempt:
Failed to execute goal org.asciidoctor:asciidoctor-maven-plugin:1.5.5:process-asciidoc (generate-docs) on project organization: Execution generate-docs of goal org.asciidoctor:asciidoctor-maven-plugin:1.5.5:process-asciidoc failed: Plugin org.asciidoctor:asciidoctor-maven-plugin:1.5.5 or one of its dependencies could not be resolved: Failure to find io.spring.asciidoctor:spring-asciidoctor-extensions:jar:0.1.1.RELEASE in https://repo.maven.apache.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 -> [Help 1]
I checked thier GitHub and looked around to find out that theres nothing in the maven repo (obvious from error) and in this question found that the repo is in https://repo.spring.io/release. Is there a way to reference a dependency to a repo directly? If not what can i do?
You can add the repo.spring.io repository to your pom.xml.
<repositories>
<repository>
<id>spring-repo</id>
<url>https://repo.spring.io/release</url>
</repository>
</repositories>
With that declaration in place you will be able to resolve this dependency:
<dependency>
<groupId>io.spring.asciidoctor</groupId>
<artifactId>spring-asciidoctor-extensions</artifactId>
<version>0.1.1.RELEASE</version>
</dependency>
More details in the docs.
Note: it is not possible to explicitly associate this dependency with that repository. Maven walks through the repositories in order of their declaration until a given dependency is resolved (or not) however if all of your other dependencies are resolved from Maven Central then the only dependency left to be resolved from repo.spring.io will be spring-asciidoctor-extensions.
I ran into this issue as well. My misconception at first was that I expected the dependencies to be resolved from the repositories section. However turns out that it's rather the pluginRepositories section. Like so:
<pluginRepositories>
<pluginRepository>
<id>spring-repo</id>
<url>https://repo.spring.io/release</url>
</pluginRepository>
</pluginRepositories>

mave 3.2 not able to access local nexus instance return 502 code

While accessing local nexus repository which is in local host the return code is 502.
pom.xml looks something like this
<repositories>
<repository>
<id>nexus</id>
<name>nexusPublic</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
To OP and anyone who may have got here through google (just like me):
I had the same issue, the project I entered used some artifact from the repository on our server (via Archiva). I was able to reach the jar from browser, but Maven was not able to find it.
The problem was that my company uses proxy and it was impossible to connect to company's server through it's own proxy. I added <nonProxyHosts>servername.dev.company.com</nonProxyHosts> to my Maven configuration (.m2/settings.xml).
According to this answer, in your case it would be <nonProxyHosts>*localhost*</nonProxyHosts>.
Question is already answered but let me write full xml configuration file:
.m2/settings.xml
<settings>
<proxies>
<proxy>
<id>proxy_http</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy host</host>
<port>porxy port</port>
<nonProxyHosts>local.net|host_1|host_2|host_3</nonProxyHosts>
</proxy>
</proxies>
</settings>

Local Nexus Repository Acting Like A Proxy For Some Maven Artifacts

I am using my own version of the Nexus web app repository installed on my local machine. I have Nexus configured with only one repository, the one where I store my snapshots:
http://localhost:8081/nexus/content/repositories/MySnapshots/
Note that after the Nexus installation I removed all the default repositories and added just my own. (Perhaps this was a bad idea?)
When I do a mvn clean install I noticed that some of the 3rd party artifacts are downloading straight from the remote repository. For example, here is one of the output lines from the build:
Downloading: http://repo.maven.apache.org/maven2/com/sun/org/apache/xml/internal/resolver/...
The strange thing is that I see other artifacts are going through my local Nexus to ultimately get to the artifact:
Downloading: http://localhost:8081/nexus/content/repositories/MySnapshots/org/apache/maven/wagon/wagon-provider-api...
Notice how the first part of the download url is my local repository but everything after MySnapshots is from apache.org.
It's almost like my Nexus repository is acting like a proxy to maven.apache.org for some artifact downloads but for others it goes straight to the source.
Can anyone tell me why this is happening?
I would't be bothered so much by this if all my builds succeeded all the time but sometimes, when I am compile large projects, I get build failures due to not being able to find an artifact.
For example, when I try to build another project that depends on eclipse jdt stuff I get the following error:
Downloading: http://localhost:8081/nexus/content/repositories/MySnapshots/eclipse/jdt/core/eclipse.jdt.core
Could not find artifact eclipse.jdt.core:eclipse.jdt.core
I am not sure if this means that my Nexus is not configured properly or if there really is no artifact eclipse.jdt.com. If the downloads were not going through my local Nexus repository I would then investigate the pom/settings.xml files. Instead this makes me wonder if it's due to my Nexus configuration.
If you would like to see my settings.xml for Maven and my pom file for the project I am building when I see this you can view them here:
settings.xml: http://pastebin.com/NvLr5bEA
pom.xml: http://pastebin.com/PJ0P3RaK
If you like to use the local nexus as a proxy as usual than you have to configure the settings.xml like this:
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</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>
The tricky thing is the mirror thing which reroutes every call to the configured nexus instance.
Things you mentioned like eclipse parts can be problematic, cause only a few artifacts are available via maven central. Furthermore you should leave the defaults like maven central, release repository and the snapshots repository unchanged, cause these are the repository you need.
I don't think its a proxy issue , upto my understanding for the first case when it is downloading from Maven Central Repo , it might be possible that same artifact is not available in your nexus repository , that's why it is going to Maven Central Repo.
In the second case it is available in your nexus so reactor didn't try to download it from Maven Central Repo.

maven repository proxy confusion

I am using maven 3.0 ( with nexus setup ) for building my projects and am getting build failures :
Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Could not find artifact directory:apacheds-core:jar:${apacheds_version} in central (http://localhost:8081/nexus/content/repositories/central)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:945)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:940)
My basic confusion is : When maven sees a dependency in the pom.xml , how does it go about looking for artifacts in remote repositories ?
My current understanding is :
It will first look in the local repo ( .m2/repository ).
If it does not find there , then it will try to search the repository specified in settings.xml under repository tag.
Question : Does it try all the repositories mentioned . or Just the first one ? Below I have mentioned 5 repos : does maven search all these one by one or just the first one ?
<repositories>
<repository>
<id>central</id>
<url>http://localhost:8081/nexus/content/repositories/central</url>
</repository>
<repository>
<id>remote</id>
<url>http://localhost:8081/nexus/content/repositories/remote-proxy-nexus-central</url>
</repository>
<repository>
<id>thirdParty</id>
<url>http://localhost:8081/nexus/content/repositories/thirdparty</url>
</repository>
<repository>
<id>codehaus</id>
<url>http://localhost:8081/nexus/content/repositories/codehaus-snapshots</url>
</repository>
<repository>
<id>public</id>
<url>http://localhost:8081/nexus/content/groups/public</url>
</repository>
</repositories>
My last confusion is about proxies section in the settings.xml. What are these locations :
<proxy>
<id>remote-proxy-nexus-central</id>
<active>true</active>
<protocol>http</protocol>
<host>repo1.maven.org/maven2</host>
<port>8080</port>
</proxy>
I can tell you we use a local Nexus and have all our users have the following in their settings.xml:
<mirror>
<id>our-mirror</id>
<name>Org Public Mirror</name>
<url>http://host/nexus/content/groups/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
This causes any call by maven to go to Nexus to get a dependency. You are right about maven first looking in local .m2.
Nexus proxies many repositories and has a union of them all (for the maven processes calling it).
This means that a developer's local maven knows only of a single repository: Nexus. Nexus will serve all the needed dependencies id they are in one of its proxied/hosted repositories.
As for Proxy, we have an organization proxy, but the Nexus is in the org (it has the proxy configured to allow access to the outer world), so maven does not need this specific configuration.
I hope this gives you some information to get started.
I strongly urge you to look into Nexus/Maven related configurations at: http://www.sonatype.org/
The correct setup for using Maven with Nexus is documented in the book Repository Management with Nexus. The sample settings.xml is here. Read the description and note that you need to add the overrides for the central repository to enable snapshots.
Once you have done that you do NOT configured a proxy in your settings.xml since it will be available in your local network without a proxy (typically). Instead you configure the proxy settings in Nexus so that it in turn can get out to the repositories like Central that you are proxying. The global proxy configuration is documented here and if required you can also configure specifics per proxy repository e.g. if you need a username/password for a repository you are proxying because it is private..

mvn install error again

mvn install
i get the following error
[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its
dependencies could not be resolved: Failed to read artifact descriptor for org.
apache.maven.plugins:maven-resources-plugin:jar:2.5: Could not transfer artifact
org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to central (http:/
/repo.maven.apache.org/maven2): Connection to http://repo.maven.apache.org refus
ed: Connection timed out:
I tried to set proxy using the earlier answers in stack but still i am facing the problem.
A clear step thru help is required.
Solution:
Add the below dependency to pom.xml:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</dependency>
Then run "mvn clean install" from command prompt.
After that refresh (F5) and upgrade the project configuration in eclipse (run > Maven > Update Project Configuration.)
Faced the same problem. This happens because of cached files. What worked for me was deleting the contents of repository folder. It did download all the files again at the next build but solved the problem.
Add a global settings.xml(sample will be available inside your mvn.home/conf/settings.xml) in your .m2 folder, that resides inside the c:/user/username/.m2 ..
Add the following entry in the settings.xml within
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
This would solve the above issue.
I had the same problem caused by proxy Setting. I solved it adding my proxy setting in the setting.xml file located under the maven installation directory in /conf/settings.xml
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>xxxx</username>
<password>xxxxx</password>
<host>xxxxxxx</host>
<port>xxxx</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
I solved this problem by including the following lines in my
settings.xml
file which can be found at C:\Program Files\Apache\maven\apache-maven-3.3.9\conf
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>https</protocol>
<host>xxxxxxxxxx</host>
<port>xxxx</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
Please pay attention to protocol- "https" not "http". Save this file and update user settings of your IDE by navigating to
Windows->Preferences->Maven->User Settings->User Settings to
C:\Program Files\Apache\maven\apache-maven-3.3.9\conf\settings.xml
Hope this helps.
In eclipse go to Window-->Preferences-->Maven-->
Unselect options "Do not automatically update dependencies from remote repositories"
Doing so has done the trick for me. I was then able to download all dependencies.

Resources