Non-resolvable parent POM using Maven 3.0.3 and relativePath notation - maven-3

After migrating to Mavent 3.0.3 Parent poms in several Projects cannot be resolved anymore.
The Projects are structured in a default manner, so I set
parent.relativePath to "../pom.xml"
superpom (located in repository)
|-rootpom (located locally: no error)
|-|-parentpom (located locally: error resolving parent)
|-|-|-module1 (located locally: error resolving parent)
|-|-|-module2 (located locally: error resolving parent)
|-|-|-module3 (located locally: error resolving parent)
|-|-|-module4 (located locally: error resolving parent)
The Error...
Non-resolvable parent POM for myGroup:myArtifactId:1.0: Failure to
find myGroup:myParentArtifactId:1.0 in
http://myRepo.net/archiva/repository/maven2 was cached in the local
repository, resollution will not be reattempted until the update
interval of maven2 has elapsed or updates are forced and
'parent.relativePath' points at wrong local POM #
myGroup:myParentArtifactId:1.0, C:\myProjectDir\parent\pom.xml, line
x, column y -> [Help 2]
... seems to indicate that the pom was searched for in the repository, so I wonder why the pom was not found locally before looked elsewhere.
I have read that maven3 might get confused when several repositories are defined in the settings.xml, but that was always when searching for a pom inside repositories and not locally.
update
Up until now we did execute the maven build on the parent-project level (parentpom) - a fact which I did not know was important, since maven2 completed successfully until now.
When using maven3 this seems to be of importance.
When executing maven3 on the root-project level (rootpom) the build finishes successfully.
So my immediate problem is solved.
Since I don't necessarily want to answer my own question maybe
someone can explain why maven3 behaves this way now or why the old
approach was wrong.

Make sure you Double-Check that the version you refer to in the child-pom is the same as that in the parent-pom. For me, I'd bumped version in the parent and had it as 3.1.0.0-RELEASE, but in the child-pom, I was still referring to the previous version via relativePath, and had it defined as 2.0.0.0-SNAPSHOT. It did not make any difference if I included just the parent directory, or had the "pom.xml" appended to the directory:
<parent>
<artifactId>eric-project-parent</artifactId>
<groupId>com.eric.common</groupId>
<!-- Should be 3.1.0.0-RELEASE -->
<version>2.0.0.0-SNAPSHOT</version>
<relativePath>
../../EricParentAsset/projects/eric-project-parent</relativePath>
</parent>

Here is answer to your question.
By default maven looks in ../pom.xml for relativePath. Use empty <relativePath/> tag instead.

'parent.relativePath' points at wrong local POM #
myGroup:myParentArtifactId:1.0, C:\myProjectDir\parent\pom.xml
This indicates that maven did search locally for the parent pom, but found that it was not the correct pom.
Does pom.xml of parentpom correctly define the parent pom as the pom.xml of rootpom?
Does rootpom folder contain pom.xml as well as the paretpom folder?

I had the same problem. My project layout looked like
\---super
\---thirdparty
+---mod1-root
| +---mod1-linux32
| \---mod1-win32
\---mod2-root
+---mod2-linux32
\---mod2-win32
In my case, I had a mistake in my pom.xmls at the modX-root-level. I had copied the mod1-root tree and named it mod2-root. I incorrectly thought I had updated all the pom.xmls appropriately; but in fact, mod2-root/pom.xml had the same group and artifact ids as mod1-root/pom.xml. After correcting mod2-root's pom.xml to have mod2-root specific maven coordinates my issue was resolved.

You need to check your relative path, based on depth of your modules from parent if module is just below parent then in module put relative path as:
../pom.xml
if its 2 level down then
../../pom.xml

Please check in logs if you have http.HttpWagon$__sisu1:Cannot find 'basicAuthScope' this error or warning also, if so you need to use maven 3.2.5 version, which will resolve error.

<parent>
<groupId>com.test.vaquar.khan</groupId>
<artifactId>vk-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../projectname/pom.xml</relativePath>
</parent>
Add following line in parent
<relativePath>../projectname/pom.xml</relativePath>
You need relative path if you are building from local parent pom not available in nexsus, add pom in nexus then no need this path

For me, it works when I double checked the parent´s "group ID" and "artifact ID" that in my case were the wrong ones and that was the problem.

Related

I am migrating a project from maven to bazel and getting error

i am following the official bazel documentation for migrating from maven to bazel and used rules_jvm_external to defined external dependencies in workspace file and Build file. But I am getting the follwing error.
C:/users/kunal_visoulia/_bazel_kunal_visoulia/3f5dzdsz/external/maven/BUILD:1212:1: in deps attribute of jvm_import rule #maven//:commons_digester_commons_digester: rule '#maven//:xml_apis_xml_apis' does not exist
ERROR: Analysis of target '//:everything' failed; build aborted: Analysis of target '#maven//:commons_digester_commons_digester' failed; build aborted
INFO: Elapsed time: 724.364s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (4 packages loaded, 371 targets configured)
Fetching #remotejdk11_win; Restarting.
i am using private nexus repo and also the official maven repo. Please help
I've successfully reproduced your error and found the following workaround:
Add xml-apis:xml-apis:1.4.01 and junit:junit-dep:4.9 to your
list of artifacts.
Add the version_conflict_policy = "pinned"
attribute to maven_install.
The root cause is https://github.com/bazelbuild/rules_jvm_external/issues/250. The missing dependencies are artifacts that relocated to new GAV coordinates, which the coursier resolver cannot handle yet. The general workaround is to manually add the legacy GAV coordinates into maven_install.
Specifically, xml-apis:xml-apis:2.0.2 relocated to xml-apis:xml-apis:1.0.b2 (but 1.4.0.1 wasn't relocated), and junit:junit-dep:4.9 relocated to junit:junit.

Failed build - path to project is a directory

The path to my project is /project/
My build file structure is src/main/package/subpackage/Class.java
My test file structure is src/test/package/subpackage/Test.java
I would like my compiled code to be in bin/main/package/subpackage/Class.class
Compiled test code in bin/test/package/subpackage/Test.class
My pom.xml has the entry
<build>
<sourceDirectory>${project.basedir}/src/main</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test</testSourceDirectory>
<outputDirectory>${project.basedir}/bin/main</outputDirectory>
<testOutputDirectory>${project.basedir}/bin/test</testOutputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
</build>
Running mvn clean install causes the following.
Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project Hello-Maven: Error loading property file '/project/': /project (Is a directory) -> [Help 1]
...
[Help 1] https://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Now I've tried the link, but it suggest that it's an issue with the plugins.
However, commenting this block out, and running mvn clean install again returns an almost empty jar file inside /project/target/Hello-Maven-1.0-SNAPSHOT.jar, containing only the pom and the manifest. Additionally, there aren't any plugins, only dependencies: junit and javafx.
EDIT: I realize that plugins specifically for running maven but finding information over why the error happens for "install" is difficult at best.

Keep backward compatibility for Maven assembly plugin from 2.4 to 2.4.1

The project has the following structure:
M
+---A
+---B
| +---B1
| +---B2
|
+---C
+---D
Every folder (M,A,B,B1,B2,C,D) contains a pom.xml file.
The pom.xml file from B1 contains the following lines:
<configuration>
<filters>
<filter>B/B1/PATH_TO_FILE_X</filter>
</filters>
</configuration>
Running
mvn clean install -Px -Dy -X
from the M folder:
using assembly plugin 2.4, everything works fine. It looks for path\M\B\B1\PATH_FO_FILE_X and it exists. (absolute path = project path + specified path)
using assembly plugin 2.4.1 (or 2.5.3), the file is not found. It looks for path\M\B\B1\B\B1\PATH_TO_FILE_X and there is a java.io.FileNotFoundException. (absolute path = submodule path + specified path)
I can manually change every path that cannot be resolved, but it's too risky because some paths can be resolved in a wrong way. If there is B\B1\PATH_TO_ANOTHER_FILE_X in B\B1\ it could cause problems.
Is there a generic method to solve this problem (keeping backward compatibility from 2.4 to 2.4.1)?
Details:
Maven 3.2.1
Java 7
Windows 7
Update:
It seems to be related to maven-filtering 1.2 that was introduced in 2.4.1:
http://maven.40175.n5.nabble.com/Apache-Maven-Assembly-Plugin-Version-2-4-1-Released-td5801647.html
https://jira.codehaus.org/browse/MASSEMBLY-686
https://jira.codehaus.org/browse/MSHARED-161
http://jira.codehaus.org/browse/MWAR-301
http://mail-archives.apache.org/mod_mbox/maven-announce/201211.mbox/%3C1791127681.01353276825400.JavaMail.Dennis#Dennis-Dator%3E
The following line from 2.4:
<mavenFilteringVersion>1.1</mavenFilteringVersion>
was replaced by
<mavenFilteringVersion>1.2</mavenFilteringVersion>
in 2.4.1.

maven "rerun with -feature" when compiling scala

I recently noticed Scala compiler warnings that maven was generating that looked like this:
[WARNING] warning: there were 4 deprecation warning(s); re-run with -deprecation for details
[WARNING] warning: there were 3 feature warning(s); re-run with -feature for details
[WARNING] two warnings found
It was not immediately apparent to me how to follow the warning's instructions so I could get details on how to change my code.
Just to make it clearer from Philip's answer (as specified on the plugin page), add the following to your pom.xml file:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
...
<configuration>
<args>
<arg>-deprecation</arg>
<arg>-feature</arg>
</args>
</configuration>
</plugin>
It turns out that these two instructions are coming from the Scala compiler and so what needs to happen under the covers is for scalac to be called with -deprecation or -feature as described here:
http://www.scala-lang.org/files/archive/nightly/docs-2.10.3/manual/html/scalac.html
(actually I never saw the -feature option explained anywhere but I was able to specify it as follows)
I'm using the scala-maven-plugin and compiling with scala:compile described here:
http://davidb.github.io/scala-maven-plugin/compile-mojo.html
The relevant parameter is described here:
http://davidb.github.io/scala-maven-plugin/compile-mojo.html#addScalacArgs
So, two maven commands that I found helpful were:
mvn clean compile -DaddScalacArgs=-deprecation
mvn clean compile -DaddScalacArgs=-feature

Maven transitive dependencies

I have 3 maven projects: first - "A" with packaging jar, second - "B" packaging jar, third - "C" packaging jar. "C" depends on "B" as compile time dependency, "B" depends on "A" also as compile time dependency. Project "C" also uses classes from "A". So I have transitive dependency C -> B -> A. But when I try to build these projects maven failed with compilation error while compiling project C: it can't find classes from project "A" that is used in "C".
I thought that maven resolves transitive dependency. Why I get such an error?
Maven resolves transitive dependencies, but will not (usually) automatically build them for you. You can get maven to do what you want by supplying the --also-make/-am flag along with the project list:
mvn -am -pl C clean install
This assumes that A, B, C are all modules of a shared parent, and you would be running the command above in the parent's directory.
The failure of transitive dependency in Maven occurs due to many reason. You need to enable debugging option for that.
I faced similar issue. I am using eclipse. To enable debug option for maven in eclipse: Windows->Preference->Maven->Tick mark Debug Output
Error in my project was:
[WARNING] The POM for mil-pop2:java-json:jar:1.0 is invalid, transitive dependencies (if any) will not be available: 4 problems were encountered while building the effective model for mil-pop2:java-json:1.0
[ERROR] 'dependencies.dependency.systemPath' for java-json.jar:java-json.jar:jar must specify an absolute path but is ${project.basedir}/src/main/resources/lib/java-json.jar #
The reason for failure in transitive dependency is the project in which we are dependent inherits the jar from custom path rather than local repository. Remove the custom path if you have provided.
Before :
<dependency>
<groupId>java-json</groupId>
<artifactId>java-json.jar</artifactId>
<version>1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/java-json.jar</systemPath>
</dependency>
After:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
This solved my error.

Resources