Pom.XML Maven Build Dependency of POM Only Looking for Jar - java

GIVEN:
I have an in house tool built with gradle that includes a dependency that is only a POM file which in turn then includes a bunch of other dependencies. No jar for this particular dependency by itself. The tool builds.
I have a maven project with a pom.xml file that I want to include this tool in because of all the company specific methods needed for some processes. I added the dependency with the type of pom and when I build it fails.
ERROR:
[ERROR] Failed to execute goal on project <MYPROJECT>: Could not resolve dependencies for project <MYPROJECT>:jar:0.0.326: <com.pom.only.dependency>:jar:7.0 was not found in <Company Repo where this POM file exists> during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of <company repo> has elapsed or updates are forced
REQUEST:
I have tried making the tool a fat jar in the hopes it would not need this. But it does. The my project builds without this tool jar so I know it is this jar that brings in the dependency. I just have no idea how to resolve this.
ALMOST CODE EXAMPLE
Because of company specific, I can not put the exact POM code but I can put what it looks like removing company specific stuff.
<dependency>
<groupId>com.group</groupId>
<artifactId>tools-app</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>com.group</groupId>
<artifactId>pom only dependency</artifactId>
<version>7.0</version>
<type>pom</type>
</dependency>
So tools app is the one that I am pulling it. It is the gradle build and uses the pom only dependency without any issue. If I pull this into a gradle app it works fine and builds. However, in the app that has this in the pom, if fails for above. So I add the dependency for the pom only dependency and mark it as type pom but still get the error.

So for my situation (and not the best solution), I went into the dependency that has only a pom and pulled the dependencies out of there and built. It worked. But feel there should be a way to make it work without having to do this.

Related

Pull dependencies as a jar in maven?

Is there a way I can pull some specific jar directly as a dependency defined in maven?
I have a maven project which has some internal and external dependencies. I am hosting this project on a maven registry so I can consume it in other projects. I am creating a jar and as well as creating "jar-with-dependencies" using the maven-assembly plugin in my project. Then I am hosting this on the maven repository where it has the pom, jar, and jar-with-dependencies all hosted.
In the other maven project, I want to pull the above maven project as a dependency. When I am trying to directly define it as a dependency as mentioned below, it is trying to pull the dependencies of the original project too in which some of the internal ones it could not find. Is there a way so that it can pull the hosted jar-with-dependencies directly or some other solution to this problem.
P.S. I do not want to host all those internal dependencies directly on the maven registry.
Update: I tried adding dependency with the help of the maven classifier to point to jar-with-dependencies. But it still does not resolve the issue
<dependencies>
<dependency>
<groupId>com.myproject.project</groupId>
<artifactId>project-java-sdk</artifactId>
<version>1.0.0-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
</dependencies>

maven add dependency located on a local repository

I have a maven project from Github, I fork it, and then I imported it to eclipse. It contains three maven modules. I added a fifth one.
Now I want to add this fifth (new) as a dependency to one of the previous modules.
I did the install in maven, and I got the jar located in my local repository. now when I added a dependency to a one of the previous modules, i got error that my new models doesn't exist in the public dependency. I mean:
Failed to execute goal on project moquette-broker: Could not resolve dependencies for project org.eclipse.moquette:moquette-broker:jar:0.7: Failure to find org.eclipse.moquette:moquette-configurationmanager:jar:0.7 in https://repo.eclipse.org/content/repositories/paho-releases/ was cached in the local repository, resolution will not be reattempted until the update interval of Paho Releases has elapsed or updates are forced -> [Help 1]
my question is how can I tell eclipse to search in my local repository as well?
I tried to upload my dependency to a public repository but it doesn't make any sence now because i am still developing
could you help please
the jar in my local repository
this is what i put in the pom in order to call my new module
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>moquette-configurationmanager</artifactId>
<version>${project.version}</version>
<scope>Test</scope>
</dependency>
and the image that i published is my local repository, because i can see that from my eclipse, like this:
After reading the first 28 comments and responses to your question, I still cannot imagine the cause of this strange error, so you'll have to debug it a bit more:
Two recommendations to debug the Maven build:
Whatever test you run, execute mvn --debug <phase> and analyze carefully the produced log.
Run mvn dependency:build-classpath to ask Maven where are the downloaded libraries referenced in the classpath.

add external jar to our dependency

There is a jar file lets say "abc.jar" which maven dependency does not exist(ie created a jar by using java command of own classes). I want to add this jar as maven dependency so that at build time it will automatically copy that jar in lib folder as like other maven dependency. how i will do. please help .
Add it as a dependency with a system scope. See the docs here.
However, rather than adding it as a system dependency it might be better to mavenize the jar itself, then you can build and install it into your dependency management system.
Also, see this question: Can I add jars to maven 2 build classpath without installing them?
You can use the systemPath attribute in the dependency tag in the POM file of your project.
In your pom.xml, use the following snippet corresponding to abc.jar:
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>abc</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>{path_to_abc.jar}</systemPath>
</dependency>
</dependencies>
The scope parameter corresponding to this artifact must be set to system, for the artifact to be picked up from the specified systemPath.
Hope this helps!
A normal maven dependency is always resolved by looking into a repository. So you must put your JAR file into a repository.
You could install your JAR into your local repository. Have a look at the install plugin. The install-file goal is your friend.
If other developers also need this JAR (because they are working with the same project), they either need to install it locally too, or - better - you deploy the JAR to a remote repository. Have a look at the deploy plugin. Here the deploy-file goal is your friend. For deploying artifacts, you need a repository manager like Nexus or Artifactory.
However, a dependency could also have the system scope (look at the other answers).

how to convert pom.xml to build.xml

Am a new bee in this area.
Got a part in pom.xml like below which i need to change in ant buid.xml.
How do i do it? Can i get any help from tutorial or anyone can explain what
<dependency>
<groupId>com.ask.core</groupId>
<artifactId>wzlogging</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
</exclusion>
</exclusions>
</dependency>
In theory it's possible to generate a ANT build file (using XSLT?), but one would need to understand the logic that each plugin implements. In practice only simple Maven builds are feasible candidates.
ANT and Maven are very different build technologies. In ANT you explicitly write all the build logic into the "build.xml" file. Maven on the other hand has most of it's functionality baked in. The "pom.xml" contains no logic instead is used to document meta information about the project (for example the list of dependencies).
Coming from an ANT world this can be very confusing, especially when you want to customise your build. In Maven this is done by declaring plugins, which understand the standard build life-cycle and are able to insert themselves at the correct part of your build.
The purpose of this long-winded explanation is to understand that it's really impossible to know what your plugin is doing by only looking at the POM file.
#Perception recommended ivy. The following answer is related (Convert from ANT to Maven):
Converting Ant Web Application Project to Maven Project
Maven and ant are very different tools.
Ant is a build tool primarily, this means it knows how to compile and package source code and run tests, but has no ability to manage project dependencies. Ant uses build.xml files to define where to find the source code and which steps to take to build your project.
Maven is more than just a build tool, it is a project management tool. It allows you to define dependencies in the pom.xml project definition, as well build, test and distribute the application. It also allows sub projects, parent projects and there exist many plugins for many other features. Maven will automatically download the dependencies and manages these dependencies between projects.
Simply put, it is not possible to just convert a Maven POM project into an Ant build.
There are alternatives that allow binary maven dependencies to be utilized within ant builds. Have a look at the Ivy dependency manager for instance.
Maven has a useful Ant plugin to generate a Ant build file from Maven pom.xml easily.
Use this maven goal: mvn ant:ant.
In eclipse: Simple generate another run-configuration for a maven build. Name it "Antfile generate". In field "Goals" Enter ant:ant. Apply these changes to you new run configuration. Typ run to start the build. In console log you get an message
[INFO] Wrote Ant project for PROJECTNAME to .

Add a dependency in Maven

How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.
You'll have to do this in two steps:
1. Give your JAR a groupId, artifactId and version and add it to your repository.
If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds:
mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile
You can also deploy it to your internal repository if you have one, and want to make this available to other developers in your organization. I just use my repository's web based interface to add artifacts, but you should be able to accomplish the same thing using mvn deploy:deploy-file ....
2. Update dependent projects to reference this JAR.
Then update the dependency in the pom.xml of the projects that use the JAR by adding the following to the element:
<dependencies>
...
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
You can also specify a dependency not in a maven repository. Could be usefull when no central maven repository for your team exist or if you have a CI server
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>commons-utils</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/commons-utils.jar</systemPath>
</dependency>
Actually, on investigating this, I think all these answers are incorrect. Your question is misleading because of our level of understanding of maven. And I say our because I'm just getting introduced to maven.
In Eclipse, when you want to add a jar file to your project, normally you download the jar manually and then drop it into the lib directory. With maven, you don't do it this way. Here's what you do:
Go to mvnrepository
Search for the library you want to add
Copy the dependency statement into your pom.xml
rebuild via mvn
Now, maven will connect and download the jar along with the list of dependencies, and automatically resolve any additional dependencies that jar may have had. So if the jar also needed commons-logging, that will be downloaded as well.
I'd do this:
add the dependency as you like in your pom:
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
run mvn install it will try to download the jar and fail. On the process, it
will give you the complete command of installing the jar with the error message. Copy that command and run it! easy huh?!
I'll assume that you're asking how to push a dependency out to a "well-known repository," and not simply asking how to update your POM.
If yes, then this is what you want to read.
And for anyone looking to set up an internal repository server, look here (half of the problem with using Maven 2 is finding the docs)

Categories