Command line tool to republish existing jar to a maven repository.
URLs
-
Project home (this page)
Do you want to improve this page? Please edit it on GitHub. |
Description
Context
When you use some of the Eclipse libraries published on Maven Central, not all their dependencies have proper metadata.
The reason is that maven have an other place where to get third party dependencies. This is the Eclipse Orbit project. The problem is that its downloads section do not use a maven repository but a P2 repository.
When you are in a regular maven or gradle job, consuming jars from a P2 repository is not straight forward. Maven repositories are more standard and way easier to use.
This project is about being able to take a jar from anywhere and a POM from maven-central, in order to republish the jar in a maven repository.
Technical details
When doing a publication, several operations are made. Step by step:
-
The jar and optionally the source jar are downloaded from an URL
-
The pom is downloaded form maven central and transformed
-
The effective pom is calculated (using the Apache Maven Help Plugin)
-
Optionally coordinates (
groupId
,artifactId
,version
) are changed -
The pom is flattened (using the Maven Flatten Plugin)
-
A comment about the transformation is added
-
-
The jars and the pom are published in a local folder
Comment added to the modified pom
The published pom has following comment, so that it is possible to understand where it comes from.
<!--
Original jar location: https://download.eclipse.org/eclipse/updates/4.14/R-4.14-201912100610/plugins/com.ibm.icu_64.2.0.v20190507-1337.jar
Original source jar location: https://download.eclipse.org/eclipse/updates/4.14/R-4.14-201912100610/plugins/com.ibm.icu.source_64.2.0.v20190507-1337.jar
Original POM: com.ibm.icu:icu4j:64.2
POM created by the tool: https://jmini.github.io/repub-jar
-->
Usage
Usage: repub-jar [-hV] --input-artifact-id=<inputArtifactId>
--input-group-id=<inputGroupId> --input-jar=<inputJarUrl>
[--input-sources-jar=<inputSourcesJarUrl>]
--input-version=<inputVersion>
[--output-artifact-id=<outputArtifactId>]
[--output-group-id=<outputGroupId>]
[--output-version=<outputVersion>] [--repository=<repository>]
[--working-dir=<workingFolder>]
-h, --help Show this help message and exit.
--input-artifact-id=<inputArtifactId>
artifactId of the input pom
--input-group-id=<inputGroupId>
groupId of the input pom
--input-jar=<inputJarUrl>
url of the jar used as input
--input-sources-jar=<inputSourcesJarUrl>
url of the sources jar used as input
--input-version=<inputVersion>
version of the input pom
--output-artifact-id=<outputArtifactId>
artifactId of the output artifacts, when not defined the
artifactId of the input pom is used
--output-group-id=<outputGroupId>
groupId of the output artifacts, when not defined the groupId
of the input pom is used
--output-version=<outputVersion>
version of the output artifacts, when not defined the version
of the input pom is used
--repository=<repository>
Folder path (relative to the working folder or absolute) of
the maven repository where the artifacts are published. By
default 'repository' inside the working folder is used
-V, --version Print version information and exit.
--working-dir=<workingFolder>
Path of the working folder, when not defined a toporary
folder is used
Example
To download the com.ibm.icu_64.2.0.v20190507-1337.jar
jar together with its source
jar from the https://download.eclipse.org/eclipse/updates/4.14/R-4.14-201912100610/ P2 Update site.
The corresponding pom in Maven Central is com.ibm.icu:icu4j:64.2
.
Command to publish the jar in a local maven repository with the pom coming from maven central:
repub-jar --input-jar=https://download.eclipse.org/eclipse/updates/4.14/R-4.14-201912100610/plugins/com.ibm.icu_64.2.0.v20190507-1337.jar \
--input-sources-jar=https://download.eclipse.org/eclipse/updates/4.14/R-4.14-201912100610/plugins/com.ibm.icu.source_64.2.0.v20190507-1337.jar \
--input-group-id=com.ibm.icu \
--input-artifact-id=icu4j \
--input-version=64.2 \
--output-group-id=patched.com.ibm.icu \
--output-version=64.2.0.v20190507-1337 \
--working-dir=output
The command creates following output:
output/repository/
└── patched
└── com
└── ibm
└── icu
└── icu4j
└── 64.2.0.v20190507-1337
├── icu4j-64.2.0.v20190507-1337-sources.jar
├── icu4j-64.2.0.v20190507-1337-sources.jar.md5
├── icu4j-64.2.0.v20190507-1337-sources.jar.sha1
├── icu4j-64.2.0.v20190507-1337-sources.jar.sha256
├── icu4j-64.2.0.v20190507-1337-sources.jar.sha512
├── icu4j-64.2.0.v20190507-1337.jar
├── icu4j-64.2.0.v20190507-1337.jar.md5
├── icu4j-64.2.0.v20190507-1337.jar.sha1
├── icu4j-64.2.0.v20190507-1337.jar.sha256
├── icu4j-64.2.0.v20190507-1337.jar.sha512
├── icu4j-64.2.0.v20190507-1337.pom
├── icu4j-64.2.0.v20190507-1337.pom.md5
├── icu4j-64.2.0.v20190507-1337.pom.sha1
├── icu4j-64.2.0.v20190507-1337.pom.sha256
└── icu4j-64.2.0.v20190507-1337.pom.sha512
Download
The tool is hosted on maven central.
<dependency>
<groupId>fr.jmini.utils</groupId>
<artifactId>repub-jar</artifactId>
<version>1.1.0</version>
</dependency>
It is available as regular jar. Jbang is really convenient to run it:
jbang run fr.jmini.utils:repub-jar:1.1.0 --help
A self executing jar is available as well:
Source Code
As for any java project, the source code of the plugin is available in the src/ folder.
Build
This project is using gradle.
Command to build the sources locally:
./gradlew build
Command to run the tool locally, passing the --help
argument to the application:
./gradlew run --args="--help"
Command to deploy to your local maven repository:
./gradlew publishToMavenLocal
Command to build the documentation page:
./gradlew asciidoctor
The output of this command is an HTML page located at <git repo root>/build/docs/html5/index.html
.
For project maintainers
signing.gnupg.keyName
and signing.gnupg.passphrase
are expected to be set in your local gradle.properties
file to be able to sign.
Command to upload the documentation page on GitHub pages:
./gradlew gitPublishPush
Command to perform a release:
./gradlew release -Prelease.useAutomaticVersion=true
Using ssh-agent
Some tasks requires to push into the distant git repository (release task or updating the gh-pages
branch).
If they are failing with errors like this:
org.eclipse.jgit.api.errors.TransportException: ... Permission denied (publickey).
Then ssh-agent
can be used.
eval `ssh-agent -s` ssh-add ~/.ssh/id_rsa
(source for this approach)
Get in touch
Use the RepubJar issue tracker on GitHub.
You can also contact me on Twitter: @j2r2b