search
HomeJavajavaTutorialJeKa: The Simplest Way to Publish on Maven Central

JeKa: The Simplest Way to Publish on Maven Central

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:

  1. A ZIP file containing documentation.
  2. 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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

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

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

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

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

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

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

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]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

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

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

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)