I have a parent project xxx-third, which has nothing but a pom declaring some dependencies and build configurations.
After I deploy it to the nexus and I can find it in the nexus web,I declare this xxx-thrid as my parent project of myProject.
Howerver, I still have the maven error complaining that Cound not find artifact com.myCom:xxx-third:pom:2.0-SNAPSHOT # com.myCom:myProject.
But if I do install locally with the code, the problem will resolve, this is annoying! Why and how to solve it?
It is because this artifact is in your local .m2 repository on your local machine, but can't be downloaded from remote respository by your build server.
The local repostiory is in path:
{USER_HOME}\.m2\repository\
You can copy the required dependency from your local repository to the local repository on your build server, then it will read the jar dependecy from local repo instead of fetching it from remote repo.
Your parent POM is not resolved. There are three options to solve this:
1) Add the parent POM to your local repository
2) Add a relativePath to your child POM pointing to your parent POM (only makes sense in a multi-module project where source is in the same repository)
<parent>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<relativePath>...</relativePath>
</parent>
3) Add a repository configuration to your settings.xml (e.g. makes sense if you have a company wide POM)
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<profiles>
<profile>
...
<repositories>
...
</repositories>
...
</profile>
</profiles>
...
As far as I understand 3) is your solution. See also:
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
https://maven.apache.org/settings.html
Related
There is a project (type=pom), which is supposed to be used as a parent for another project.
parent
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>my-firm</groupId>
<artifactId>custom-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<distributionManagement>
<repository>
<id>lib-repo-local</id>
<name>my-releases</name>
<url>http://artifactory.local:8081/artifactory/libs-release-local</url>
</repository>
<snapshotRepository>
<id>lib-repo-snapshots</id>
<name>my-snapshots</name>
<url>http://artifactory.local:8081/artifactory/libs-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
</project>
child
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my-firm</groupId>
<artifactId>custom-parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>child-sample</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<distributionManagement>
<repository>
<id>lib-repo-local</id>
<name>my-releases</name>
<url>http://artifactory.local:8081/artifactory/libs-release-local</url>
</repository>
<snapshotRepository>
<id>lib-repo-snapshots</id>
<name>my-snapshots</name>
<url>http://artifactory.local:8081/artifactory/libs-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
</project>
The parent project is deployed to the remote repository - artifact my-firm:custom-parent:1.0.0 is available.
When I run mvn clean on the child project there's an error
[FATAL] Non-resolvable parent POM for my-firm:child-sample:0.0.1:
Failure to find my-firm:custom-parent:1.0.0 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
and 'parent.relativePath' points at wrong local POM # line 7, column 11
All the three points in the error message seem to be unrelated to my intentions.
Maven does not try to look in the repo described in distributionManagement, but complaints about maven.central
Nothing is cached in local repository - all artifacts removed from there before the build.
The parent.relativePath is intentionally absent to have the child project agnostic to the parent project location and let it rely only on the deployed artifact (parent pom).
Please, show how to edit the poms to have child and parent as separate projects and let child to depend only on the parent artifact.
Please note that <distributionManagement> is only for upload. This is where Maven puts the artifacts if you run mvn deploy.
So if you want Maven to look into your artifactory for the parent POM, you need to add an appropriate <repository> element or -- which is the preferred way -- configure your artifactory in the settings.xml.
Nevertheless if you build the parent first on some machine and then build the child on the same machine, the parent POM is read from the local repository. It is not removed from there in any way. I don't know what went wrong in your case, but I guess you either had a different local repository for both builds or the content was somehow erased in between.
I am creating a maven module including a parent pom. This parent artifact is stored in a nexus maven repository. I added the nexus repository to my settings.xml.
Now if I am building my child module I am getting and error:
Could not find artifact test:my.parent:pom:1.0
It seems that the settings.xml is not used per default. If I add
<repositories><repository><id>random</id><url>http://test/repository/maven-releases/</url></repository></repositories> to my childs pom everything works fine, the settings.xml is used and the parent artifact is found.
Am I missing anything that the settings.xml will be used per default or is this the expected behaviour?
I do not want to add this random repo tag to every of my child poms.
Parent Pom:
<groupId>test</groupId>
<artifactId>my.parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
Modul Pom:
<parent>
<groupId>test</groupId>
<artifactId>my.parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>my.module</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
settings.xml
<settings>
<mirrors>
<mirror>
<id>Nexus</id>
<url>http://mynexus:8081/repository/maven-group/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<settings
As I know you can call maven by using IDE or command line.
If you are calling from IDE, check the settings if it is mapping to your settings.xml file
If you are using command line, you can check by using mvn --v and it shows you where your maven home is. Then you can check your settings file under conf/settings.xml
I'm working on a multi-module springboot-app that looks like this :
basedir
module - pom.xml
module2 - pom.xml
module3 - pom.xml <---- this project contains the Main class
pom.xml (parent pom)
and I've got a library.jar that can't be placed into our nexus for various reasons. So I've installed into to a project-local repository following with mvn install:install-file -Dfile=/path/myjar.jar -DgroupId=id.group -DartifactId=myjar -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=${project.basedir}/lib
I've added both dependency and repository into parent pom , because all 3 modules use this jar
...
<dependency>
<artifactId>myjar</artifactId>
<version>1.0</version>
<groupId>id.group</group>
</dependency>
...
<repositories>
<repository>
<id>lib</id>
<url>file:///${project.basedir}/lib
<repository>
</repositories>
But still, the the dependency is not being found, neither by IntelliJ nor when i try to create a JAR. When i do mvn clean install it ignores the local repositry and tries to download it from the nexus. Could it be my company setting.xml config that is at fault or is it the multi-module setup?
Your supplied sample seems faulty (the URL tag is not closed) - you could try to install your maven dependency locally as you did and then use the maven offline switch and see if it works
mvn -o install
I made a simple Maven project for my class. According to the teachers tutorial we cannot upload it to our school repo due to some server issues, so we have to store it locally using altDeploymentRepository. I have the following pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dpp</groupId>
<artifactId>simple_lib</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository>internal.repo::default::file://${project.basedir}/../${project.name}-mvn-repo</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
</build>
</project>
So in the directory with my Maven project I have two directories:
sample_lib
sample_lib-mvn-repo
In the second one, deep down in : sample_lib-mvn-repo\com\dpp\sample_lib\1.0-SNAPSHOT I have a .jar file which I want to import (but not using just .jar file like passing the path to it - I need to do this "Maven way", import it as Maven lib). Can I do it if the file is not stored on any remote repository, but on my hard drive?
Running simply mvn install will install the file in your local repository. The local repository, by default, is in your home directory, under .m2\repository.
Using your pom above, after running mvn install, you would have jar (and some other files) in .m2\repository\com\dpp\sample_lib\1.0-SNAPSHOT.
To import this subsequently in another project, you would create a dependency in that project's pom like:
<dependency>
<groupId>com.dpp</groupId>
<artifactId>simple_lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
This all takes place only on your machine, and will not use any remote repository.
Now you have a local simulation of a repository.
You can import it using the repository tag as described in https://maven.apache.org/pom.html#Repositories. To specify a file make it a file url like file:
Yes, you can add maven repository and point it to a local directory:
<repository>
<id>local</id>
<name>local</name>
<url>file:${user.dir}/sample_lib-mvn-repo</url>
</repository>
https://maven.apache.org/guides/introduction/introduction-to-repositories.html
Given that your jar file is here sample_lib-mvn-repo\com\dpp\sample_lib\1.0-SNAPSHOT.jar, you then can add it as a dependency:
<dependency>
<groupId>com.dpp</groupId>
<artifactId>sample_lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
It's not exactly what you're asking. But a quick and dirty solution is to make a POM project (no source code).
Inside the POM project you have the main and external projects.
You can simply make a dependency on the other project.
I'm new to maven, and trying to understand how to release my project. I have the following project setup in svn:
trunk
|-deployer
| |-pom.xml
|-webapp
| |-pom.xml
|-utils
|-pom.xml
While developing webapp, I always want to develop against the latest snapshot version of utils, so I declare the dependency on utils in webapp/pom.xml via:
com.company
utils
1.0-SNAPSHOT
Webapp itself is also currently versioned at version 1.0-SNAPSHOT. It's pom.xml has the declaration:
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Sample Webapp</name>
So everything is working great, but now I want to release my software. In deployer, I have the following in pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>deployer</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Project Release</name>
<modules>
<module>externals/webapp</module>
</modules>
<properties>
<url.svn>http://<my-server>/<project>/trunk</url.svn>
</properties>
<scm>
<connection>scm:svn:${url.svn}</connection>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3</version>
<configuration>
<tagBase>
http://<my-server>/<project>/tags
</tagBase>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>Releases</id>
<name>Releases</name>
<url>http://<nexus-server>/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>Snapshots</id>
<name>Snapshots</name>
<url>http://<nexus-server>/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
Within the deployer folder itself I have a folder called "externals" which has an svn-externals set to check out my webapp project (I added this because maven complained about not being able to find it), so my modules path should be correct.
Questions
1.) I want to release a version of my web app, but when I run a mvn release:prepare and mvn release:perform in my deployer project, my only tangible output is my trunk tagged in svn and a pom uploaded to my nexus repository. This makes sense in that my deployer artifact packaging is type "pom", but it also doesn't get the job done of getting me a war of my webapp (I should note here that if a do a release in the webapp project by itself though, that I will get the war). I need to release multiple modules, and so I thought I could use maven aggregation from the deployer project to accomplish this, but it doesn't seem to be working.
2.) Is there a better way to achieve what I am trying to do?
Thank you for any insights you can provide.
You should run the maven-release-plugin against each module that you intend to release. I've never seen someone have a special "deployer" module that releases the other modules, this is not how things are commonly done.
Normally to release the webapp module you would run the commands against the webapp module, and to release the utils module you would run the commands against the utils module.
If you have a parent module that ties webapp and util together then I believe you can just run the release commands against that.
As matt b says, simply adding a maven-release-plugin entry at the top pom will probably do what you want. If you want to collect several artifacts into a proper release bundle, you want to create a module for this, but then you want to look at the maven assembly plugin. It can collect various jars (wether from modules or external dependencies) and resources into a directory, zip file or similar.