Automate creation of pom file dependencies based on the jar file - maven

I have hundreds of jar files scattered across different projects that I need to create pom file dependencies files for. I'd really like to avoid manually searching for every jar file and adding the dependency manually. Is there an API I can use to accomplish this task or some other way ?
Ive tried using a generic pom as described : http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html
Using this command - mvn install:install-file -Dfile=spring-webmvc-portlet-3.0.6.RELEASE -DgroupId=test -DartifactId=test -Dversion=version -Dpackaging=jar-DgeneratePom=true
But should the generated pom not match the jar file ? Or do I need to add this myself
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>version</version>
<packaging>jar-DgeneratePom=true</packaging>
<description>POM was created from install:install-file</description>
</project>

I wrote a script that generates an ivy file. It uses the jar checksums to identify the matching modules in Maven central.
https://github.com/myspotontheweb/ant2ivy
This solution could be adapted to generate a Maven POM.

You may create a bash script which uses the Maven Install plugin to produce a generic POM.
See http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html

Related

Can you create a jar file from pom.xml during a Gradle build?

A build I am running needs to have access to a jar file that does not exist in our Nexus repository as only the pom.xml file does.
I am able to create the jar file locally using the just mentioned pom.xml file, but the Gradle build job is written to pull jar files from Nexus and not locally. And I do not have the ability to load the local jar file to our Nexus repo.
With the above in mind, is it possible to have the Gradle build job create the jar file from the pom.xml during the build (i.e. on the fly)?
Thank you.
Here is the pom.xml file's contents used to create the jar file - not sure if this is the best way or not.
<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.apache.logging.log4j </groupId>
<artifactId>log4j</artifactId>
<version>2.17.0</version>
<packaging>jar</packaging>
</project>
`
Sure, you can use maven publish gradle plugin. You can use this plugin to build a jar and publish to maven repository, or your private nexus repositor. This is the docs: https://docs.gradle.org/current/userguide/publishing_maven.html

How to use smartics-jboss-modules maven plugin in maven project

We can create module.xml manually and keep it in modules folder of Jboss. But to autogenerate it, there is a plugin called smartics-jboss-modules-maven-plugin. Has anyone implemented it in maven project. My requirement is to generate module.xml and module from maven project and automatically add it to jboss modules folder. I need to know the exact steps to implement it in my project.
and inside that particular folder make sure you create a file that complies with the following model
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
</project>
As documented in here:
https://www.smartics.eu/confluence/display/SJBMMP/The+smartics+JBoss+Modules+XSD

What are .pom files in Maven build artifacts?

You can see from browsing any repository that Maven build artifacts contain .pom files. The contents of these files look a whole lot like pom.xml files. Where do these files come from? What are they used for? Additionally, build artifacts have maven-metadata.xml files, at least on search.maven.org, and these files have substantially the same content as the .pom files. What's the deal with that?
The files are the pom files from within the project. Those are deployed to the maven repository during the release build or by other build tools as well (gradle, ivy, etc.).
Those files are needed to describe the dependencies of the appropriate artifact otherwise you have no other opportunity to store such kind of information.
In your particular example (really old 2005) this is a pom file which is created at a time of times where maven was not such distributed. In this case the file does not contain any dependencies.
If you take a look here:
http://search.maven.org/#browse%7C-77609479
you see a number of versions of a single artifact. If you now take a look into the maven-metadata.xml you will see list of available versions.
The best answer I have found so far is in this SO thread. Here is an exact quote, highlighting the crux of the explanation:
Every jar needs to have a pom file describing it, you can just add something simple like this:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aGroup</groupId>
<artifactId>aArtifactId</artifactId>
<version>aVersion</version>
<packaging>jar</packaging>
<name>a Name</name>
</project>
Another good explanation:
POM that is installed to Nexus will describe the jar. Used to pull the
dependencies that are associated to corresponding jar. When we add the
jar as dependency to our project, all the jars required for the
included jar will be identified through the corresponding pom.

Getting rid of version from JAR file in Maven POM?

In pom.xml, I've below entry which I'm using to create a JAR
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>se.sigma.educational</groupId>
<artifactId>my-jar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Executable jar example</name>
....
Here, everything works fine & JAR gets created with name "my-jar-1.0.jar". Is there a way that I can create the JAR file name as "my-jar.jar" instead of having version within the name??? I tried removing attribute but then the pom.xml fails to run.
Any help is much appreciated, how do I get rid of version from the JAR file name?
Thanks!
Well, there is a <finalName> property which lets you define a custom name of an artifact -
<build>
<finalName>NAME_OF_JARFILE</finalName>
</build>

Why Maven is looking for .pom file when .jar is present in the repository?

I have the following dependency in my pom.xml
<dependency>
<groupId>aGroup</groupId>
<artifactId>anArtifact</artifactId>
<version>aVersion</version>
</dependency>
I also have the anArtifact-aVersion.jar file in ~/.m2/repository/aGroup/anArtifact/aVersion directory.
When I start building the project, maven looks for a .pom file instead of using the .jar file and attempts to download the following
http://repo1.maven.org/maven2/aGroup/anArtifact/aVersion/anArtifact-aVersion.pom
How can I configure maven to use the existing .jar file?
Every jar needs to have a pom file describing it, you can just add something simple like this:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aGroup</groupId>
<artifactId>aArtifactId</artifactId>
<version>aVersion</version>
<packaging>jar</packaging>
<name>a Name</name>
</project>
Run your build using the "-o" switch to use Maven in offline mode. In offline mode, Maven will not check for updates of snapshot dependencies in remote repositories.
the best way to install an artifact to the local repository which were not built by Maven ist to use
mvn install:install-file ...
have a look at the install:install goal.
POM that is installed to nexus will describe the jar. Used to pull the dependencies that are associated to corresponding jar. When we add the jar as dependency to our project, all the jars required for the included jar will be identified through the corresponding pom.
It is looking for the pom to, among other things, resolve the transitive dependencies.

Resources