Home Java javaTutorial JeKa: The Simplest Way to Publish on Maven Central

JeKa: The Simplest Way to Publish on Maven Central

Dec 30, 2024 pm 09:28 PM

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
Copy after login
Copy after login

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
Copy after login
Copy after login

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)
        );
    }

}
Copy after login

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
    }

}
Copy after login

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
Copy after login

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 of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? Apr 19, 2025 pm 09:51 PM

When using TKMyBatis for database queries, how to gracefully get entity class variable names to build query conditions is a common problem. This article will pin...

See all articles