Maven dependency resolution fails because properties are not substituted - maven-3

We've been working on a maven (3.0.5) project for a couple of months now, and suddenly we're getting this error when establishing new dev environments (without a local maven repository):
[ERROR] Failed to execute goal on project [100's of dependencies truncated]: Failed to read artifact descriptor for org.apache.httpcomponents:httpclient:jar:${httpcomponents.version}: Could not transfer artifact org.apache.httpcomponents:httpclient:pom:${httpcomponents.version} from/to nexus (http://bob.premitech.net:8081/nexus/content/groups/public): Illegal character in path at index 96: http://bob.premitech.net:8081/nexus/content/groups/public/org/apache/httpcomponents/httpclient/${httpcomponents.version}/httpclient-${httpcomponents.version}.pom -> [Help 1]
I'm using a multi-module project, and the obvious thing you might think is wrong is that ${httpcomponents.version} isn't defined. Except it is defined as 4.2.5 in the parent pom. Even wierder, hardcoding the version instead of using the property does not change the error message.
I've even tried removing the http components dependency entirely. This also does nothing. The only thing that does work is manually copying the correct dependency into the local maven repository (.m2), which completely defeats the purpose of using maven in the first place.
Does anybody have the slightest idea what could be wrong here? Is there some kind of caching mechanism I'm not aware of?

As you said, even hard-coding the version in your POM still giving you such error, it seems to me that the "incorrect" version is coming from other dependencies transitively. IIRC, place holders of dependencies are not replaced in Maven.
For example, your foo project is depending on your own bar-framework, both foo and bar-framework is depending on httpcomponent. In bar-framework you are also using property place holder for the version. In such case , if you built bar-framework in that new machine with problem, for which the bar-framework POM contains the un-substituted property of httpcomponent version. Then even your foo project is correct, Maven will still need to resolve the incorrect httpcomponent because of transitive dependency.
Try to do mvn dependency:tree to see how you are getting the dependency in your project. This may give some hints.

Related

How to read settings from Jenkins in Gradle?

I use Jenkins to build Gradle, but there was a problem when reading the settings.
I use the 'net.linguica.maven-settings' plugin and in build.gradle wrote the line:
mavenSettings { userSettingsFileName = project.property('maven.settings.location) }
And now I can run the build like this:
gradle -Pmaven.settings.location=/u01/test.xml clean build publish
But when building, I get dependency errors.
Could not resolve org.springframework.boot:spring-boot-configuration-processor:2.1.6.RELEASE.
Required by:
project :
Skipped due to earlier error
Could not resolve org.junit.jupiter:junit-jupiter-api:5.8.0.
What do I need to do?
Maven doesn't intrinsically know where to get dependencies from. It will look to the setting.xml for a list of repositories and look for any dependencies from there. If you list multiple repositories is will check each one until it finds the dependencies listed in the pom file.
I suspect because you are overriding the settings the file you are using doesn't have a repository listed which has the dependency you need.
That is what the error message is telling you - "I looked though all the registries I know about but couldn't find org.junit.jupiter:junit-jupiter-api:5.8.0 in any of them"
You can read a bit about it here https://maven.apache.org/settings.html under "Repositories"

Groovy/Grails unable to resolve class only # run

Have a groovy controller leveraging Java SSH package (JSch) with NO ISSUES in IDE (jar was added to library, import works, all calls against class pass) however I get failure only on run-app:
unable to resolve class JSch # ... : JSch jsch = new JSch()
I use the same code in Java without any issues for an SFTP application and this won't even instantiate the initial object so less concerned about the rest of the code. I've tried mucking with dependency mgmt and refreshing with no success.
I guess the question at hand is why does any class fail to resolve only at run when there are no obvious issues with implementation?
Yeah... Grails doesn't give a damn about which jars you add with your IDE. Grails uses Maven to resolve dependencies.
Next steps
The first thing is to remove the JSch jar. Then, add the following Maven artifact to your project: com.jcraft:jsch:0.1.53
Of course, adjust the version number as needed. How this is added to Grails depends on the version of Grails you're using.
Grails 3
Add the following to the dependencies closure in build.gradle:
compile 'com.jcraft:jsch:0.1.53'
Grails 2.4
For Grails 2.4 (and maybe earlier versions, I simply don't know) add the following within the plugins closure in grails-app/config/BuildConfig.groovy
compile 'com.jcraft:jsch:0.1.53'

Failure in maven site plugin version 3?

I am trying to get a project to run the maven site:site goal using Maven 3.0.4. Unbeknownst to me, it had been running under Maven 2.2.1 (when I thought it should have been 3).
I keep getting the following failure:
Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:site (default-cli) on project myproj-parent: Execution default-cli of goal org.apache.maven.plugins:maven-site-plugin:3.0:site failed: For artifact {null:null:null:jar}: The groupId cannot be empty.
How do I even find what artifact is missing groupId?
It turns out the POM file for one of my dependencies was corrupt. The POM for joda-jsptags-1.0.2 in our Nexus repository wasn't a POM, but a fragment of HTML.
Getting a clean version of joda-jsptags fixed this issue.
It was just frustrating not to get any sort of idea what was bad. And apparently the Maven 3 plugins are more strict on POM parsing.
If you are migrating from Maven 2.2.1 to Maven 3.0.4 you have to be aware of some difference in particular in relation with site generation. You should have taken a look the the migration docs and take a look if your pom needed to be fixed.
Missed a link.

Project build error: Non-resolvable parent POM in maven

Project build error: Non-resolvable parent POM guide.ide.eclipse:guide-ide-eclipses:1.0-SNAPSHOT for guide.ide.eclipse:guide-ide-eclipse:0.0.1-SNAPSHOT: Failed to resolve POM for guide.ide.eclipse:guide-ide-eclipses:1.0-SNAPSHOT due to Missing:
1) guide.ide.eclipse:guide-ide-eclipses:pom:1.0-SNAPSHOT
1 required artifact is missing.
for artifact:
guide.ide.eclipse:guide-ide-eclipses:pom:1.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2, releases=true, snapshots=false)
Bit late in answering this but... as I've been bitten this afternoon by something similar...
Have you checked out How do I use Maven through a proxy?
The answers there are pretty helpful and relate to proxy issues which may relate to your problem. My own answer there relates to "parent not found" and "parent.relativeParent points to wrong local POM" errors where the parent pom actually resides in a remote repository. I've documented the various attempts I made to resolve this issue (with credits), ultimately changing how I configured the proxy for maven.
My friend was getting the same error. Actually he was connected to his companies VPN. He just disconnected with the VPN and then force updated the project and it started working fine.

Grails Dependency Resolution

I'm a bit of a Grails newbie. I have an app which works fine in Eclipse but when I deploy in production falls over because of missing dependencies.
When I run the dependency report it shows all the dependencies are automatically present for 'build' but absent for 'runtime'.
What's the neatest way to migrate the dependencies from to runtime so (I hope) they get copied into my war file?
Also, I'm using the sanitizer plugin. This runs fine in development but has the dependencies missing from 'runtime' so falls over. If I manually add, for example, one of the dependencies into BuildConfig.groovy ("org.owasp.antisamy:antisamy:1.4.3") then grails falls over with this error:
loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/xml/sax/SAXParseException"
I'm assuming that this is a classpath issue but I'm not sure why this only happens when I manually add the dependency - surely it's present all the time?
You're right, you have to add missing runtime dependencies to BuildConfig.groovy. The simplest thing would be to copy them from the plugin's BuildConfig.groovy to your app's one. You should also raise a JIRA for the respective grails plugin to get this fixed upstream.
Lots of jars out there in the Maven repositories have their dependencies not correctly defined in their pom file.
There is a way to fix that in BuildConfig.groovy, by switching off transitivity:
runtime('org.owasp.antisamy:antisamy:1.4.3') {
transitive = false
}
Instead of 'transitive=false' you might also experiment with excluding only specific dependencies using e.g.
excludes "xml-apis", "xerces"
inside the 'runtime' closure.

Resources