Maven trying to download '-sources.src' artifacts? - maven

I have a Maven project that so far used to compile without problems. Today, when I run mvn clean package -U, I get:
[ERROR] Failed to execute goal on project myproj: Could not resolve dependencies for project org.myorg.myproj:myproj:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: javax.servlet:javax.servlet-api:src:sources:3.0.1, org.eclipse.jetty:jetty-servlet:src:sources:8.1.2.v20120308, org.eclipse.jetty:jetty-server:src:sources:8.1.2.v20120308, org.eclipse.jetty:jetty-webapp:src:sources:8.1.2.v20120308, commons-io:commons-io:src:sources:2.4: Could not find artifact javax.servlet:javax.servlet-api:src:sources:3.0.1 in MyRepo (http://maven.myorg.org:9001/nexus/content/repositories/myrepo/) -> [Help 1]
I tried to with a fresh local Maven repository (rm -fr ~/.m2/repository) but that did not make any difference.
Why does Maven try to find source/src artefacts? Any ideas where the problem might lie?
Edit: My dependencies (as seen using mvn help:effective-pom) do not have any source classifiers. For example, the dependency on the jetty-server mentioned in the error message reads as follows:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.2.v20120308</version>
<scope>compile</scope>
</dependency>
Solution: With the help of #AlessandroSantini and #brian-topping, I finally identified the problem. One of my indirect dependencies had a <classifier>sources</classifier> and <type>src</type>. (mvn help:effective-pom did not show these indirect dependencies, and mvn dependency:tree failed with the above error message, too; eventually, a grep -r 'jetty-server' ~/.m2/repository/ -C 3 identified the artifact with the messed up dependency.)
It turned out that one of my own SBT projects required the (non-existing) source artifacts for one of its dependencies: I used SBT's withSources() where I should have used sbteclipe's EclipseKeys.withSource := true to get the sources in Eclipse.

Do you have any dependencies on public snapshots? I'd take a look at the output of mvn dependency:tree and see if you can find a transitive dependency that is including the sources somehow. Maybe one of the transitives have changed since your last build and they messed something up.

Related

Errors with Maven install on a project

I'm trying to install Maven on a project (with mvn clean install) but I have some errors and I don't know what they mean.
Here is the screen shot of the cmd :
I also add the right environment variables for maven (M2, M2_HOME and MAVEN_OPTS).
Can someone help me and tell me what it means please ?
It means that your dependency to eu.akka.jbossas:jboss-as-client:7.1.7.Final that you have specified in your POM is not available at Maven central. Do you have the jar file available somewhere?
If that is the case, run this:
mvn install:install-file -Dfile=<your jar file> -DgroupId=eu.akka.jbossas -DartifactId=jboss-as-client -Dversion=7.1.7.Final -Dpackaging=jar
Please bear in mind that this means that only the machine you are running on will be able to build your project. If other developers/machines also need to build this project, consider installing a central repository at your site, such as Nexus or Artifactory, and upload the jar file there. You will then also need to make Maven aware that it should fetch the dependencies from there.
The error tells you that the maven dependency eu.akka.jbossas:jboss-as-client doesn't exist. I've checked the url where it should be and it doesn't exist.
You should check other dependencies. For example the one maven provides:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-appclient</artifactId>
<version>7.1.1.Final</version>
</dependency>
If you've got the jar local, you can create a maven-dependency by using this guide.

Maven: Command line to download the dependencies described in the pom.xml

I would like to know the maven command line to download the dependencies described in the pom.xml.
It is that : mvn dependency:copy-dependencies ?
Try the dependency:go-offline goal. It's meant to be used to resolve dependencies to the local repo before using the -o switch to go to offline mode. But the goal itself has no bearing on going offline. The name may be misleading.
Goal that resolves all project dependencies, including plugins and reports and their dependencies.
Here's the details about the dependency:copy-dependencies in case you're interested
Anther option is the dependency:resolve goal
Goal that resolves the project dependencies from the repository.

How to find out which maven artifact/plugin is requesting for the download of a no longer available dependency

I was compiling an "old" open sourced project, while encountered this problem:
[ERROR] Failed to execute goal on project .... Can not transfer artifact x:y:z from ...
the artifact x:y:z is not found from all repositories defined in the project pom.xml.
After looked up the effective pom.xml, I could not find any references to x:y:z.
How can I find out which artifact or plugin is requesting a missing dependency without analyze all transitive dependencies?
If you use eclipe - you can see dep tree like this: open pom.xml and tick "Dependency Hierarchy" tab.
Also you can try to use mvn dependency:tree but I am not totally sure that it will work if some of your deps are missing.
UPDATE: seems like both eclipse and dependency:tree require sucessfull artifact resolution to work whch is not your case.
In this case I guess you're left with 3 opttions:
clean your cache (wipe everything under ~/.m2/repository), run your build and do occurence search (search for something like "problematic-artifact-id") on files in your ~/.m2/repository. One or couple of the artifacts should reference the problematic artifact in their pom. This should give you a hint.
clean your cache and run your build with -X switch. This will put maven in verbosity mode and you should find some hints about what might reference dead dependency (point your attention on download order, what artifacts got resolved, check dependencies of resolved artifacts in their poms)
dumb as hell - comment/uncomment deps in your pom and see what causes the mentioned error.

Maven and Multiple Goals

I'm attempting to use the Grails Maven plugin to build a war file. There's a known problem with the plugin in that it does not resolve range dependencies, and my project pom file must contain range dependencies.
The dependency is specified like this:
<dependency>
<groupId>mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>[0.0.0,999.999.999)</version>
</dependency>
The error message is like this:
[ERROR] Failed to execute goal
org.grails:grails-maven-plugin:2.2.1:clean (default-clean) on project
sdm: Failed to create classpath for Grails execution. Encountered
problems resolving dependencies of the executable in preparation for
its execution. Error resolving project artifact: Could not transfer
artifact mygroup.myartifact:pom:[0.0.0,999.999.999) from/to myRepo
(https://maven.mydomain/nexus/content/groups/myRepo):
IllegalArgumentException for project
mygroup.myartifact:pom:[0.0.0,999.999.999): Illegal character in path
at index 89:
https://maven.mydomain/nexus/content/groups/myRepo/mygroup/myartifact/[0.0.0,999.999.999)/myartifact-[0.0.0,999.999.999).pom
-> [Help 1]
As you can see, the range dependency is not being resolved, and a literal version "[0.0.0,999.999.999)" is being looked for.
To work around the problem, I can use the Maven version plugin and do this:
mvn versions:resolve-ranges [replaces range deps in pom file with actual versions]
mvn grails:war [builds war based on actual versions in newly modified pom file]
mvn versions:revert [reverts pom file to original state]
BUT here's my problem: if I combine these goals into one Maven command:
mvn versions:resolve-ranges grails:war versions:revert
the grails:war fails with the error I described above - it seems to be seeing the pom file in its initial state (with the range dependencies), even though the versions plugin has updated the pom file with actual version numbers. After the failure, the pom file has this:
<dependency>
<groupId>mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>2.1.15</version>
</dependency>
So my question is - why does the second goal (grails:war) see the pom file as it was at the start of the whole chain of goals, not as it is when the goal runs? How can I make the second goal (grails:war) see the pom file as it stands after completion of the first goal (versions:resolve-ranges)?

Maven POM error - POM is missing

I am trying to build a maven project. My other team members are able to build it without issues. I get the following errors:
[WARNING] The POM for org.hectorclient:hector-core:jar:1.0-3 is missing, no dependency information
available
[WARNING] The POM for org.hectorclient:hector-test:jar:1.0-3 is missing, no dependency information
available
Then the build fails with the error: Could not resolve dependencies for the project XYZ. What could be possibly going wrong?
Surely the jar is missing from your .m2 local repository.
Assuming the dependency is written in the pom.
What I suggest:
Case: When you have internet
fire mvn install that will follow your POM.xml and it will download all the necessary jars.
then fire mvn compile to build.
Case: You are having restricted internet connection that is restricting / no Internet
Take the repository + POM from other machine that is compiling successfully
then fire mvn -o compile
I assume it will solve your case.
#Vaibs You are correct. Adding to your answer:
"Check the settings.xml of yours and the others. If you are not able to download the dependencies from internet like the one you mentioned due to some reason then you will need to set up maven somewhere else and and fire "mvn install" there to get the latest dependencies and put those .m2 into yours."

Resources