Search code examples
gradlebuildpom.xmlnexus

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>

`


Solution

  • 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