Java library to help working with maven repositories.
URLs
-
Project home (this page)
Do you want to improve this page? Please edit it on GitHub. |
Usage
All the logic is in the main class: fr.jmini.utils.mvnutils.Maven
Accessing the base url of maven central
String url = Maven.MAVEN_CENTRAL_BASE_URL;
Calculate the URL of an artifact in maven central
For a POM file:
MavenArtifact artifact = new MavenArtifact("fr.jmini.utils", "mvn-utils", "1.0.0");
String url = Maven.pomMavenCentralUrl(artifact);
For a JAR file:
MavenArtifact artifact = new MavenArtifact("fr.jmini.utils", "mvn-utils", "1.0.0");
String url = Maven.jarMavenCentralUrl(artifact);
For any other type you can also provide an extension as parameter (".jar"
in this example):
MavenArtifact artifact = new MavenArtifact("fr.jmini.utils", "mvn-utils", "1.0.0");
String url = Maven.mavenCentralUrl(artifact, ".jar");
Calculate the path of an artifact in a local maven repo
For a POM file:
Path repository = Paths.get("/tmp/repository");
MavenArtifact artifact = new MavenArtifact("fr.jmini.utils", "mvn-utils", "1.0.0");
Path pomFile = Maven.pomFileInMavenRepository(repository, artifact);
For a JAR file:
Path repository = Paths.get("/tmp/repository");
MavenArtifact artifact = new MavenArtifact("fr.jmini.utils", "mvn-utils", "1.0.0");
Path jarFile = Maven.jarFileInMavenRepository(repository, artifact);
For any other type you can also provide an extension as parameter (".jar"
in this example):
Path repository = Paths.get("/tmp/repository");
MavenArtifact artifact = new MavenArtifact("fr.jmini.utils", "mvn-utils", "1.0.0");
Path jarFile = Maven.fileInMavenRepository(repository, artifact, ".jar");
Write a file in a local repository
Example for a pom file:
MavenArtifact artifact = new MavenArtifact("fr.jmini.example", "tmp", "1.0-SNAPSHOT");
String pomContent = ""
+ "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n"
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ " <modelVersion>4.0.0</modelVersion>\n"
+ "\n"
+ " <groupId>fr.jmini.example</groupId>\n"
+ " <artifactId>tmp</artifactId>\n"
+ " <version>1.0-SNAPSHOT</version>\n"
+ " <packaging>pom</packaging>\n"
+ "</project>";
Maven.writeFileToRepository(repository, artifact, ".pom", pomContent);
Handle armored files in a local repository
MavenArtifact artifact = new MavenArtifact("fr.jmini.utils", "example", "1.0-SNAPSHOT");
Path file = repository.resolve("fr/jmini/utils/example/1.0-SNAPSHOT/example-1.0-SNAPSHOT.jar");
if (!Files.exists(file)) {
fail(".jar file is supposed to exist");
}
Maven.writeArmoredFiles(repository, artifact, ".jar", Algorithm.MD_5, Algorithm.SHA_1, Algorithm.SHA_256, Algorithm.SHA_512); (1)
Path folder = file.getParent();
if (!Files.exists(folder.resolve("example-1.0-SNAPSHOT.jar.md5"))) {
fail(".jar.md5 file is supposed to exist");
}
if (!Files.exists(folder.resolve("example-1.0-SNAPSHOT.jar.sha1"))) {
fail(".jar.sha1 file is supposed to exist");
}
if (!Files.exists(folder.resolve("example-1.0-SNAPSHOT.jar.sha256"))) {
fail(".jar.sha256 file is supposed to exist");
}
if (!Files.exists(folder.resolve("example-1.0-SNAPSHOT.jar.sha512"))) {
fail(".jar.sha512 file is supposed to exist");
}
Maven.verifyArmoredFiles(repository, artifact, ".jar", Algorithm.MD_5, Algorithm.SHA_1, Algorithm.SHA_256, Algorithm.SHA_512); (2)
1 | creates the armored files |
2 | verifies the armored files |
Download
The library is hosted on maven central.
Last stable version is: 1.0.0.
<dependency>
<groupId>fr.jmini.utils</groupId>
<artifactId>mvn-utils</artifactId>
<version>1.0.0</version>
</dependency>
fr.jmini.utils:mvn-utils:1.0.0
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 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 MvnUtils issue tracker on GitHub.
You can also contact me on Twitter: @j2r2b