JeKa is a modern Java build tool focused on simplicity.
This post demonstrates how to publish to Maven Central with minimal configuration.
Prerequisite: You need an OSSRH account to publish on Maven Central.
With JeKa, you can fully configure the build by editing the jeka.properties file as follows:
jeka.version=0.11.11 jeka.java.version=17 jeka.inject.classpath=dev.jeka:nexus-plugin @nexus= @project.moduleId=com.github.djeang:vincer-dom @project.gitVersioning.enable=true # Configuration for deploying to Maven central @maven.publication.predefinedRepo=OSSRH @maven.publication.metadata.projectName=Vincer-Dom @maven.publication.metadata.projectDescription=Modern Dom manipulation library for Java @maven.publication.metadata.projectUrl=https://github.com/djeang/vincer-dom @maven.publication.metadata.projectScmUrl=https://github.com/djeang/vincer-dom.git @maven.publication.metadata.licenses=Apache License V2.0:https://www.apache.org/licenses/LICENSE-2.0.html @maven.publication.metadata.developers=djeang:djeangdev@yahoo.fr
Note that dependencies are listed in a dedicated dependencies.txt file to maintain clear separation of concerns.
To publish to Maven Central, execute: jeka project:pack maven:publish.
See a concrete example here.
Explanations
Now that you know how to do it, let's explain how it works.
Jeka and Java Versioning
For better portability and reproducibility, we can declare both the Jeka and Java versions required for building. Both versions will be automatically downloaded if not already present on the host machine.
Specify Module ID and Versioning
The published moduleId is specified using the @project.moduleId property.
The version can be explicitly specified using the @project.version property. Note that properties can be set in the jeka.properties file or passed as a command-line argument: -D@project.version=1.0.1.
Instead, we choose to rely on Git to infer the version using: @project.gitVersioning.enable=true. If there is no tag on the current commit, the version will be set to [branch]-SNAPSHOT; otherwise, it will be the tag-name.
Configure Publication Repository
@maven.publication.predefinedRepo=OSSRH instructs Jeka to publish to the pre-defined OSSRH repository. This repository is configured to publish to the OSSRH snapshot repository when the version ends with -SNAPSHOT, and to the release repository otherwise.
The repository uses the following environment variables to pass secrets:
- jeka.repos.publish.username: OSSRH account username
- jeka.repos.publish.password: OSSRH account password
- jeka.gpg.secret-key: Armored GPG secret key as a string
- jeka.gpg.passphrase: The passphrase protecting the secret key
The content of jeka.gpg.secret-key can be obtained by executing: gpg --export-secret-key --armor my-key-name.
Provide Publication Metadata
The mandatory metadata are set using @maven.publication.metadata.xxx properties.
Note that the @maven.publication.metadata.licenses property expects a format like: [license1 name]:[license1 url],[license2 name]:[license2 url],...
Automate Release Publication
For convenience, we use the Nexus plugin,
which automatically closes the staging repository without requiring manual intervention.
jeka.inject.classpath=dev.jeka:nexus-plugin instructs Jeka to fetch the plugin from Maven Central, while @nexus= activates it.
Execute Build
To publish, simply execute: jeka project:pack maven:publish.
This will:
- Create the JAR to publish (project: pack).
- Create source and Javadoc JARs.
- Generate the published POM file.
- Compute all checksums.
- Sign all published files.
- Push everything to the OSSRH repository.
To see what will be published, execute: jeka maven: info.
Fine-Tuning
Fine-tuning in Jeka is generally achieved programmatically, complementing the declarative configuration from the jeka.properties file. This approach allows for highly flexible and powerful configurations with the benefits of static typing.
Customize Transitive Dependencies
We can customize the dependencies mentioned in the published POM.
In the following example, we remove the com.google.guava:guava dependency and force the jfiglet dependency to have the RUNTIME scope.
jeka.version=0.11.11 jeka.java.version=17 jeka.inject.classpath=dev.jeka:nexus-plugin @nexus= @project.moduleId=com.github.djeang:vincer-dom @project.gitVersioning.enable=true # Configuration for deploying to Maven central @maven.publication.predefinedRepo=OSSRH @maven.publication.metadata.projectName=Vincer-Dom @maven.publication.metadata.projectDescription=Modern Dom manipulation library for Java @maven.publication.metadata.projectUrl=https://github.com/djeang/vincer-dom @maven.publication.metadata.projectScmUrl=https://github.com/djeang/vincer-dom.git @maven.publication.metadata.licenses=Apache License V2.0:https://www.apache.org/licenses/LICENSE-2.0.html @maven.publication.metadata.developers=djeang:djeangdev@yahoo.fr
Add Extra Artifacts
The API enables defining additional artifacts to publish.
In the following example, two artifacts are generated at publication time:
- A ZIP file containing documentation.
- A shaded uber JAR (a JAR that includes all classes from dependencies with renamed packages to avoid conflicts).
class Build extends KBean { @Override void init() { var publication = load(MavenKBean.class).getMavenPublication(); publication.customizeDependencies(deps -> deps .minus("com.google.guava:guava") .withTransitivity("com.github.lalyos:jfiglet", JkTransitivity.RUNTIME) ); } }
Publish on Other Repositories
To publish to a repository other than Maven Central, you can set the following properties:
class Build extends KBean { @Override void init() { var publication = load(MavenKBean.class).getMavenPublication(); publication.putArtifact(JkArtifactId.of("doc", "zip"), this::genDoc); publication.putArtifact(JkArtifactId.of("shade", "jar"), project.packaging::createShadeJar); } private void genDoc(Path targetZipFile) { // generate documentation and zip it in targetZipFile } }
Place these properties in [USER HOME]/.jeka/global.properties (instead of jeka.properties file) to keep configurations consistent across projects and avoid redundancy.
For more details, refer to the documentation.
Comparison with Maven
The following is the Maven POM configuration equivalent for deploying a project to Maven Central:
jeka.repos.publish=https://my.company/myrepo # Optional properties jeka.repos.publish.username=myUsername jeka.repos.publish.password=myPassword jeka.repos.publish.headers.Authorization=Bearer:: XHrU8hHKJHJ454==67g
Conclusion
Jeka provides a simpler, yet powerful way to build Java software and publish artifacts to Maven Central or other repositories, with much less configuration and effort than traditional tools.
Visit the website, videos, and examples to get an idea of everything Jeka can do better.
Disclaimer: I am the author of Jeka.
The above is the detailed content of JeKa: The Simplest Way to Publish on Maven Central. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)