How to use maven uber pom with dependencies? - maven

I have a simple maven plugin which in turn depends on parent pom file. The parent pom file has ten (10 number of) 3rd party jar dependencies which have been installed in my local repo using the following command.
mvn install:install-file -Dfile=foo.jar -DgroupId=com.foo.bar -DartifactId=foo1.jar -Dversion=1.1.0.0 -Dpackaging=jar
Similarly I have installed all the other 9 jars to my local repo. This is the uber pom.xml file.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.bar</groupId>
<artifactId>maven-uber-pom</artifactId>
<packaging>pom</packaging>
<version>1.1.0.0</version>
<name>maven-uber-pom</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo1.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo2.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo3.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>foo4.jar</artifactId>
<version>1.0.0.0</version>
</dependency>
:
:
</dependencies>
I am trying to reference this uber pom in my plugin's pom.xml file by the following:
<project>
<parent>
<groupId>com.foo.bar</groupId>
<artifactId>maven-uber-pom</artifactId>
<version>1.1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.bar</groupId>
<artifactId>foo-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.1.0.0</version>
<name>foo bar plugin</name>
<url>http://maven.apache.org</url>
</project>
After this I try installing my plugin using the pom.xml file by
mvn install <command>
Maven tries to download the 3rd party artifact dependencies from central repo http://repo1.maven.org/maven2 and subsequently fails. As there is no artifact which such co-ordinates which can be found in the central repo.
I have also tried using the uber-pom as a plugin dependency since I was desperate. Any ideas?

By default Maven will search for dependencies in your local repositories first. If it doesn't find, it will then search on your global/custom repositories (by default only the central repository is set). Did you run mvn install on uberpom? And if so, check if it's path is correct in your local repo.
I'm not sure if you just forgot to adapt this to your example, but "uberpom" definition has com.foo.bar as groupId and the usage on your plugin has com.oracle.weblogic.test. It's probably a typo though. I also suppose that all your 3rd party dependencies were installed correctly (check their pom).
And just for the sake of it, check if <localRepository> is set in your settings.xml. Usually you don't have to set this, but give it a shot.
I'm not any expert but I hope it helps!

The groupId in your parent POM and the groupId in the reference to the parent POM don't match. The groupId, artifactId, and version must match exactly in order for Maven to find the parent.

Try mvn install -o to force offline mode. Out might point out the problem.
When you ran the install-file command, did you specify generate pom and generate checksums?
Manually check your maven repo for the jars to see if they installed properly.

Related

Maven version ranges : release vs snapshot version

With Apache Maven 3.3.9, We are using maven ranges for some dependencies version resolution as there are a lot of maven modules in my application an keeping the specific dependency version and changing to each release is bit pain.
To ilusstrate the structire of current application its like
pom.xml (parent)
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<version>0.0.5-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parentpom</name>
<modules>
<module>../myapp-service</module>
</modules>
<dependencies>
<dependency>
<groupId>com.someotherapp</groupId>
<artifactId>someotherappA</artifactId>
<version>[1.1.0, 1.2.0)</version>
</dependency>
<dependency>
<groupId>com.someotherapp</groupId>
<artifactId>someotherappB</artifactId>
<version>[1.1.0, 1.2.0)</version>
</dependency>
</dependencies>
pom.xml (child module)
<parent>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<version>[0.0.1,2.0.0)</version>
<relativePath>../myapp/pom.xml</relativePath>
</parent>
<groupId>com.myapp.service</groupId>
<artifactId>myapp-service</artifactId>
<version>1.0.9-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myapp-service</name>
<dependencies>
<dependency>
<groupId>com.someotherapp</groupId>
<artifactId>ssomeotherappA</artifactId>
</dependency>
<dependency>
<groupId>com.someotherapp</groupId>
<artifactId>someotherappB</artifactId>
</dependency>
</dependencies>
EXPECT : I expect the child module should pick the last released dependency version(no snapshot) like someotherappA-1.2.0 and not the latest version ´someotherappA-1.2.1-SNAPSHOT´
PROBELM : If available dependency version in artifactory are like ´someotherappA-1.2.1-SNAPSHOT´(latest snapshot) and ´someotherappA-1.2.0´(stable release), then maven artifact ´myapp-service´ pick SNAPSHOT dependencies rather release version,even tough i am specifying -DallowSnapshots=false which means snapshot versions are not allowed in maven version ranges.
Here is what i am using to build my child module
mvn versions:resolve-ranges -f "myapp-service/pom.xml" -DgenerateBackupPoms=true -DallowSnapshots=false -DprocessDependencyManagement=false -DprocessParent=true
mvn clean install
I found similar problem here how do I stop maven version ranges from using snapshots and seems there is an open bug in maven https://issues.apache.org/jira/browse/MNG-3092 . However, I am looking possible workaround or solution if someone bypassed this similar problem.

Inherit child-dependencies from maven dependency

I have two separate maven projects.
Project A contains utility classes and similar stuff. It also uses jetbrains annotations in some interfaces to mark parameters as Nullable and NotNullable.
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
Project B uses some of the Utilities of Project A. It includes it as a dependency from my repository.
<dependency>
<groupId>org.test.group</groupId>
<artifactId>Utilities</artifactId>
<version>1.0</version>
</dependency>
I can access the classes from my utilities dependency just fine. But i do not see any of the annotations on the parameters. I also can't access the jetbrains annotations in project B in any of my classes there. I'd have to add the jetbrains dependency in project B as well to do so.
Is there any way to inherit the dependencies of another dependency?
I looked at other questions and found this similar one. Tho his solution was to set the optional-parameter to false which i am not even using. Perhaps also something that needs to be configured in the maven build? Currently im running my build with goals clean package deploy without any special additional configuration.
I know gradle builds allow for implementation and api dependencies, where one of them forwards the dependency to other projects that include it and the other doesn't.
Edit: Here the full configuration of my projects
Local nexus running under localhost:8081 containing my artifacts. Local TeamCity running under localhost:8080 used for the builds and deployment to the repository.
Project A 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>org.test.group</groupId>
<artifactId>Utilities</artifactId>
<version>1.0</version>
<name>Utilities</name>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test.group/</url>
</repository>
</distributionManagement>
</project>
Project B 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>org.test.group</groupId>
<artifactId>TestProject</artifactId>
<version>1.0</version>
<name>TestProject</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.test.group</groupId>
<artifactId>Utilities</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test.group/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test.group/</url>
</repository>
</distributionManagement>
</project>
Edit 2:
I've made some progress. Since i didn't change Project A's version after adding the annotations my local repository didn't fetch the new version. After a purge using mvn dependency:purge-local-repository the updated state of version 1.0 was available.
mvn dependency:tree prints now
[INFO] org.test.TestProject:jar:1.0
[INFO] \- org.test:Utilities:jar:1.0:compile
[INFO] \- org.jetbrains:annotations:jar:20.1.0:compile
Tho my IDE (Intellij) still doesn't recognize the annotation classes inside TestProject. Any idea why this is failing now?
You inherit annotations automatically, no configuration needed.
You don't inherit it, if it is of scope provided. Look at mvn dependency:tree to find out about the place and scope of the annotations library.
BTW: mvn clean package deploy is a waste of time, just use mvn clean deploy.
The issue was caused by my local maven repository. Since i didn't change the version of Project A's artifact (always 1.0) my local repository kept providing me with the old state of version 1.0.
Using mvn dependency:purge-local-repository i was able to cleanse the old 1.0 and load the new 1.0. Tho still my IDE refused to imports annotations dependency. At this point it was listed by mvn dependency:tree tho.
After tempering with the IDE for a while i decided to update my version to 1.1. Once Project A's 1.1 was built and Project B's dependency was updated to 1.1 it worked.
So basically it resulted from poor versioning of my projects, which interfered with my local maven repository.

jboss maven project add jar not exist in public repository

I need to add a jar not exist in publi repo to my maven project i have using system scope like this :
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
<scope>system</scope>
<systemPath>${user.home}/jars/my.jar</systemPath>
</dependency>
This solution working fine in local machine but not in distant server. when i google it i find that system scope is aleardy a bad practice so there is another solution to add a jar to project?
You have two options here.
First:
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
Second:
Install this jar in your local repository and it will be included in your built project.
You can add jar in you local repository like this:
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
Where: <path-to-file> the path to the file to load
<group-id> the group that the file should be registered under
<artifact-id> the artifact name for the file
<version> the version of the file
<packaging> the packaging of the file e.g. jar
Edit your pom.xml
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
</dependency>

Non-resolvable parent POM: Could not transfer artifact org.springframework.boot

I am creating simple spring boot web application
I am using the project generated by spring Initializer
I have set my JDK and maven in the path
Also done setting for JAVA_HOME
While running the application getting following error
Non-resolvable parent POM: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.3.RELEASE from/to central (http://repo.maven.apache.org/maven2): This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server (repo.maven.apache.org) and 'parent.relativePath' points at no local POM # line 14, column 10 -> [Help 2]
following is my POM in the project
<?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.iot.tme</groupId>
<artifactId>PowerBIDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PowerBIDemo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
try to update maven dependencies by hands mvn dependency:purge-local-repository.
Incase you're working for an organisation and need VPN to work. You must connect to VPN before downloading the dependencies. This is what resolved my issue.
In my case, I was using wrong JDK version (1.7) and changing it to (1.8) worked.
For me what worked was that I downloaded the cacerts file provided in the same repository and stored that in the JAVA_HOME/jre/lib/security folder and then I right clicked the Project in the Package Explorer view of Eclipse, Project -> Maven -> Update Project (Alt+F5), and after that it started downloading the dependencies, from the various repos which were unreachable earlier, and later the problem got resolved.
I changed jdk 1.7 to jdk 1.8 and It worked and Don't forget also update your environment variables.
i have already answered it here.
try deleting the dependencies in .m2 and update and clean.
and also check the settings.xml is properly configured in window-->preferences-->maven-->User Settings.
For me it work by changing option settings of Netbeans.
Tools > Options > Team > Maven > Maven Home
Update by downloading maven manually from original website
check maven by using mvn -v. extra inst.(http://maven.apache.org/install.html)
Once Maven is installed, add the maven directory to Maven Home:
Tools > Options > Team > Maven > Maven Home

Maven project with prebuilt jar

Currently I am not using Maven in any way whatsoever, but since I am writing a library I would like other developers to be able to use it as a Maven dependency. It seems like the easiest way to do this would be to have a Maven project which just contains the jar.
However, all the examples I've seen of pom.xml have build logic in them and I was wondering how I am supposed specify the prebuilt jar as the resulting artifact.
Thanks!
I do not know if I understand you correctly, so maybe I am commenting something totally different.
If you want to offer your project as Maven dependency for other projects, the project must be somewhere to be downloaded (Maven central repository, your company Nexus...) and your project must have something to identify it: groupId, artifactId and the version. You can specify these separately when installing the artifact, or you can provide a pom that contains this metadata, along with dependencies if there are any. Both approaches are explained here.
Then adding something like this in the project that wants your project as dependency, it should work.
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-a</artifactId>
<version>1.0</version>
</dependency>
Still, since you control this project, you might want to consider converting your library to a Maven project to reap other benefits of Maven (in some IDEs like Eclipse there is an option that convert a regular Java Project in a Maven project), and in the generated pom.xml is the info which is mention above.
Here an example of a basic pom.xml to be a jar.
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Extracted from here --> http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Resources