In our pom.xml, I need to set the version of the parent project to an environment variable:
example:
<parent>
<groupId>edu.university.se.se_parent_project</groupId>
<artifactId>SE_ParentProject</artifactId>
<version>${parent.version}</version>
<relativePath>../SE_ParentProject/pom.xml</relativePath>
</parent>
How do I do that?
using ${parent.version} is giving me this error:
[ERROR] Non-resolvable parent POM: Could not transfer artifact edu.university.se.se_parent_project:SE_ParentProject:pom:${parent.version} from/to central
Replace ${parent.version} with ${env.PARENT_VERSION} and add this environment variable to your OS
PARENT_VERSION=1.0.0-SNAPSHOT
Related
I have two different projects. Project_1 is a maven multi-module project. Project_2 depends on some modules of the Project_2. I have declared a version property in parent POM of Project_1 and referred in the child POM like below.
Project_1 Parent POM
<groupid>x</groupid>
<artifactid>y</artifactid>
<version>${app.version}</version>
<properties>
<app.version>1.0.0</app.version>
</properties>
Project_1 Child POM
<parent>
<groupid>x</groupid>
<artifactid>y</artifactid>
<version>${app.version}</version>
</parent>
<artifactid>y1</artifactid>
Project_2 POM
<dependency>
<groupid>x</groupid>
<artifactid>y</artifactid>
<groupid>1.0.0</groupid>
</dependency>
I have installed Project_1 using "mvn clean install" in the local repository but the problem is Project_1 and its module pom and its dependencies installed in the local repo is with version ${app.version}. Due to this, If I refer the Project_1 or its modules as a dependency in Project_2 with the actual version 1.0.0, its throwing error that it can't find version 1.0.0
Is there any way to solve this? during install of Project_1, I like to override the key {app.version} with actual in the local repo.
The same can be achieved by flatten-maven-plugin.
In case of Parent version include, flatten-maven-plugin can be used with xml-maven-plugin.
I tried to build a job and it returns following error:
> Failed to execute goal
> org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument (default-cli)
> on project addressbook: Execution default-cli of goal
> org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument failed: Plugin
> org.codehaus.mojo:cobertura-maven-plugin:2.7 or one of its
> dependencies could not be resolved: Could not find artifact
> com.sun:tools:jar:0 at specified path
> /var/lib/jenkins/tools/hudson.model.JDK/myjava/../lib/tools.jar ->
> [Help 1]
Any idea how to resolve it?
I guess the jdk in question was above 8 which is still not supported by Cobertura: https://github.com/mojohaus/cobertura-maven-plugin/issues/30
[ERROR] Failed to execute goal
org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument (verification)
on project generex: Execution verification of goal
org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument failed: Plugin
org.codehaus.mojo:cobertura-maven-plugin:2.7 or one of its
dependencies could not be resolved: Could not find artifact
com.sun:tools:jar:0 at specified path
/usr/local/lib/jvm/openjdk11/../lib/tools.jar
I had to switch to https://www.jacoco.org/jacoco/ instead.
Seems like you are missing the tools jar in your JDK/JRE library you can confirm it by searching for the JAR in the lib folder if it's not present then you can add the following in your pom.xml
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
Where ${env.JAVA_HOME} points to the JAVA you set in environment variables if you are using another JRE apart from the one set then specify the path like so /var/lib/jenkins/tools/hudson.model.JDK/myjava/JDK8/lib/lib
Hope it helps :)
Container is already having wsdl4j-1.5.1.jar. I have observed that when I have written only
axis1.4 dependency code in my pom.xml, it automatically downloading axis-wsdl4j-1.5.1.jar file which is also
creating problem to my existing application. could you please let me know,
why axis jar is internally downloading wsdl file and how to remove this
internal dependency
Like we declare needed artifacts as maven dependencies in pom for our java project, artifacts(declared as dependencies) are also projects and need other artifacts(dependencies).
According to this url, artifact-axis-1.4.jar is using artifact-axis-wsdl4j-1.5.1.
That is why when you are trying to download the axis-1.4.jar, maven is automatically downloading its corresponding dependency - axis-wsdl4j-1.5.1.
If your container is providing wsdl jar then you can tell maven to not to download axis-wsdl4j-1.5.1.jar, by using the exclude tag in your pom file, like below -
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
<exclusions>
<exclusion>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
</exclusion>
</exclusions>
</dependency>
Above declaration should solve your jar clashing problem.
You can refer to this url suggested by Timo, to get the detailed explanation of exclude tag. *
I am currently facing the following problem with Maven 3 when I am trying to build the site. I will appreciate you help on this.
mvn clean site
..........
[INFO] Reactor Summary:
[INFO]
[INFO] Project A ......................................... SUCCESS [15.383s]
[INFO] Project B ......................................... SUCCESS [2.232s]
[INFO] My Site ........................................... FAILURE [0.105s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.769s
[INFO] Finished at: Fri Jun 29 14:26:04 AMT 2012
[INFO] Final Memory: 18M/150M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.1:site (default-site) on project site: SiteToolException: Unable to read local module-POM: 1 problem was encountered while building the effective model for my.com:projA:0.1-SNAPSHOT
[ERROR] [FATAL] Non-resolvable parent POM: Could not find artifact my.com:parent-pom:pom:0.1-SNAPSHOT and 'parent.relativePath' points at no local POM # line 12, column 13
[ERROR] for project my.com:projA:0.1-SNAPSHOT
.............
First here is the configuration:
Apache Maven 3.0.4 (r1232337; 2012-01-17 12:44:56+0400)
Java version: 1.7.0_04, vendor: Oracle Corporation
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.4", arch: "x86_64", family: "mac"
Nexus repository: 2.0.6
The parent POM:
<modelVersion>4.0.0</modelVersion>
<name>Parent POM</name>
<groupId>my.com</groupId>
<artifactId>parent-pom</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
The aggregation project pom:
<modelVersion>4.0.0</modelVersion>
<name>My Site</name>
<groupId>my.com</groupId>
<artifactId>site</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>my.com</groupId>
<artifactId>parent-pom</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath/>
</parent>
<modules>
<module>projA</module>
<module>projB</module>
</modules>
The pom of Project A:
<modelVersion>4.0.0</modelVersion>
<name>Project A</name>
<groupId>my.com</groupId>
<artifactId>projA</artifactId>
<version>0.1-SNAPSHOT</version>
<parent>
<groupId>my.com</groupId>
<artifactId>parent-pom</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath/>
</parent>
The pom of Project B:
4.0.0
<name>Project B</name>
<groupId>my.com</groupId>
<artifactId>projB</artifactId>
<version>0.1-SNAPSHOT</version>
<parent>
<groupId>my.com</groupId>
<artifactId>parent-pom</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath/>
</parent>
Here is the structure of the folder where I run "mvn clean site":
./pom.xml (aggregation project)
./projA/pom.xml (Project A)
./projB/pom.xml (Project B)
parent-pom is successfully deployed to NEXUS repository before the execution of mvn clean site with following command mvn deploy -DaltDeploymentRepository=snapshots::default::http://MyServer:8081/nexus/content/repositories/snapshots
And finally the problem itself:
When I run mvn clean site right after the deployment of parent-pom site is built successfully. If I delete the folder (with its content) "my" (it contains the parent-pom) from the local repository (~/.m2/repository) and then try to build the site with mvn clean site I am getting the error described at the beginning. Actually Maven downloads the parent-pom from the NEXUS. I have compared the downloaded files and files which have been generated after the deployment and have realized that few are missing, for instance maven-metadata-local.xml near to "0.1-SNAPSHOT" folder.
So when I am trying to run the site building job from Jenkins I am getting the error described above, because the parent-pom is not deployed from the machine where Jenkins run.
How can I come up with this problem or what I did wrong?
Thank you.
As pointed out by this answer, there is a bug in the site plugin, which only looks for dependencies in what it thinks is Maven central.
I am having the same problem in Maven 3.0.4 and site-plugin 3.3 . I also have the issue that it works in my development machine which is running Windows 7, but not in the CI-Server which is running Jenkins on Debian.
The problem is not in your pom files. When I built your aggregation-pom, Maven downloaded normally the parent-pom from the remote repo (after I deleted from my local repo).
Try this:
mvn -U clean install site dependency:purge-local-repository
Additionally, you could do some clean up:
remove <relativePath/> from all of them
remove <version>0.1-SNAPSHOT</version> and <groupId>my.com</groupId> from projA and ProjB (they are inherited from the parent)
I got the same problem... works on my developer MacBook, but fails on my Jenkins running on RHEL7 when running mvn site using maven-site-plugin:3.7. I did not test to downgrade the site plugin.
I found another solution. The problem in my case was the maven-project-info-reports-plugin especially the goal dependencies. If I skip the goal with -Dmpir.skip=true my site get's generated (without the dependencies :( report).
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.