All Projects → jjohannes → extra-java-module-info

jjohannes / extra-java-module-info

Licence: Apache-2.0 license
A Gradle 6.4+ plugin to use legacy Java libraries as Java Modules in a modular Java project

Programming Languages

groovy
2714 projects
java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to extra-java-module-info

dockerPreparePlugin
Gradle plugin to generate docker layer-friendly directory for spring boot applications
Stars: ✭ 44 (+12.82%)
Mutual labels:  gradle-plugin
xjc-generation-gradle-plugin
A Gradle Plugin for generating JAXB Java sources using the XJC compiler
Stars: ✭ 20 (-48.72%)
Mutual labels:  gradle-plugin
gradle-git-versioning-plugin
This extension will set project version, based on current Git branch or tag.
Stars: ✭ 44 (+12.82%)
Mutual labels:  gradle-plugin
corda-gradle-plugins
Gradle plugins used by Corda and Cordapps
Stars: ✭ 21 (-46.15%)
Mutual labels:  gradle-plugin
gradle-android-emulator
Gradle plugin for starting the Android Emulator when running instrumentation tests
Stars: ✭ 30 (-23.08%)
Mutual labels:  gradle-plugin
Robfuscate
Obfuscate the int index of R.id/R.string/R.layout… in the classes.dex of Android project
Stars: ✭ 56 (+43.59%)
Mutual labels:  gradle-plugin
chainsaw
Gradle plugin: adds support for building Java 9 modules.
Stars: ✭ 71 (+82.05%)
Mutual labels:  gradle-plugin
androidNativeBundle
a gradle plugin that support publish c/c++ headers to 'aar' and depend those 'aar'
Stars: ✭ 60 (+53.85%)
Mutual labels:  gradle-plugin
gradle-plugin-bootstrap
All you need to create a custom Gradle plugin
Stars: ✭ 24 (-38.46%)
Mutual labels:  gradle-plugin
secrets-gradle-plugin
A Gradle plugin for providing your secrets to your Android project.
Stars: ✭ 475 (+1117.95%)
Mutual labels:  gradle-plugin
StringFuck
Yet Another String Obfuscator for Android
Stars: ✭ 50 (+28.21%)
Mutual labels:  gradle-plugin
android-gradle-plugins
Gradle Plugins for Android builds
Stars: ✭ 12 (-69.23%)
Mutual labels:  gradle-plugin
gradle-versioneye-plugin
Plugin for Gradle to update your project's dependencies status on www.versioneye.com
Stars: ✭ 31 (-20.51%)
Mutual labels:  gradle-plugin
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (+33.33%)
Mutual labels:  gradle-plugin
kfc-plugins
Kotlin/JS Fast Configuration
Stars: ✭ 37 (-5.13%)
Mutual labels:  gradle-plugin
StaticBus
🚌 A static bus use in modules.
Stars: ✭ 15 (-61.54%)
Mutual labels:  gradle-plugin
metalava-gradle
A Gradle plugin for Metalava, AOSP's tool for API metadata extraction and compatibility tracking.
Stars: ✭ 29 (-25.64%)
Mutual labels:  gradle-plugin
sentry-android-gradle-plugin
Gradle plugin for Sentry Android. Upload proguard, debug files, and more.
Stars: ✭ 67 (+71.79%)
Mutual labels:  gradle-plugin
laboratory
Feature flags for multi-module Kotlin Android projects
Stars: ✭ 71 (+82.05%)
Mutual labels:  gradle-plugin
android-buddy
Transform Android project classes with Byte Buddy at compile time
Stars: ✭ 42 (+7.69%)
Mutual labels:  gradle-plugin

A Gradle 6.4+ plugin to use legacy Java libraries as Java Modules in a modular Java project.

This plugin is maintained by me, Jendrik Johannes. I offer consulting and training for Gradle and/or the Java Module System - please reach out if you are interested. There is also my YouTube channel on Gradle topics.

Special thanks goes to Ihor Herasymenko who has been contributing many features and fixes to this plugin!

If you have a suggestion or a question, please open an issue.

There is a CHANGELOG.md.

Java Modules with Gradle

If you plan to build Java Modules with Gradle, you should consider using these plugins on top of Gradle core:

Here is a sample that shows all plugins in combination.

Full Java Module System Project Setup is a full-fledged Java Module System project setup using these plugins.

How to use this plugin

This plugin allows you to add module information to a Java library that does not have any. If you do that, you can give it a proper module name and Gradle can pick it up to put it on the module path during compilation, testing and execution.

The plugin should be applied to all subprojects of your multi-project build. It is recommended to use a convention plugin for that.

Plugin dependency

Add this to the build file of your convention plugin's build (e.g. build-logic/build.gradle(.kts) or buildSrc/build.gradle(.kts)).

dependencies {
    implementation("de.jjohannes.gradle:extra-java-module-info:0.15")
}

Defining extra module information

In your convention plugin, apply the plugin and define the additional module info:

plugins {
    ...
    id("de.jjohannes.extra-java-module-info")
}

// add module information for all direct and transitive dependencies that are not modules
extraJavaModuleInfo {
    // failOnMissingModuleInfo.set(false)
    module("commons-beanutils:commons-beanutils", "org.apache.commons.beanutils") {
        exports("org.apache.commons.beanutils")
        
        requires("org.apache.commons.logging")
        requires("java.sql")
        requires("java.desktop")
        
        // requiresTransitive(...)
        // requiresStatic(...)
    }
    module("commons-cli:commons-cli", "org.apache.commons.cli") {
        exports("org.apache.commons.cli")
    }
    module("commons-collections:commons-collections", "org.apache.commons.collections")
    automaticModule("commons-logging:commons-logging", "org.apache.commons.logging")
}

Dependencies in build files

Now dependencies defined in your build files are all treated as modules if enough extra information was provided. For example:

dependencies {
    implementation("com.google.code.gson:gson:2.8.6")           // real module
    implementation("net.bytebuddy:byte-buddy:1.10.9")           // real module with multi-release jar
    implementation("org.apache.commons:commons-lang3:3.10")     // automatic module
    implementation("commons-beanutils:commons-beanutils:1.9.4") // plain library (also brings in other libraries transitively)
    implementation("commons-cli:commons-cli:1.4")               // plain library        
}

Sample uses Gradle's Kotlin DSL (build.gradle.kts file). The Groovy DSL syntax is similar.

FAQ

How do I deactivate the plugin functionality for a certain classpath?

This can be useful for the test classpath if it should be used for unit testing on the classpath (rather than the module path). If you use the shadow plugin and encounter this issue, you can deactivate it for the runtime classpath as the module information is irrelevant for a fat Jar in any case.

Kotlin DSL

configurations {
    runtimeClasspath { // testRuntimeClasspath, testCompileClasspath, ... 
        attributes { attribute(Attribute.of("javaModule", Boolean::class.javaObjectType), false) }
    }
}

Groovy DSL

configurations {
    runtimeClasspath { // testRuntimeClasspath, testCompileClasspath, ... 
        attributes { attribute(Attribute.of("javaModule", Boolean), false) }
    }
}

How do I add provides ... with ... declarations to the module-info.class descriptor?

The plugin will automatically retrofit all the available META-INF/services/* descriptors into module-info.class for you. The META-INF/services/* descriptors will be preserved so that a transformed JAR will continue to work if it is placed on the classpath.

The plugin also allows you to ignore some unwanted services from being automatically converted into provides .. with ... declarations.

extraJavaModuleInfo {               
    module("groovy-all-2.4.15.jar", "groovy.all", "2.4.15") {
       requiresTransitive("java.scripting")
       requires("java.logging")
       requires("java.desktop")
       ignoreServiceProvider("org.codehaus.groovy.runtime.ExtensionModule")
       ignoreServiceProvider("org.codehaus.groovy.plugins.Runners")
       ignoreServiceProvider("org.codehaus.groovy.source.Extensions")
    }
}

What do I do in a 'split package' situation?

The Java Module System does not allow the same package to be used in more than one module. This is an issue with legacy libraries, where it was common practice to use the same package in multiple Jars. This plugin offers the option to merge multiple Jars into one in such situations:

 extraJavaModuleInfo {
    module("org.apache.zookeeper:zookeeper", "org.apache.zookeeper") {
        mergeJar("org.apache.zookeeper:zookeeper-jute")
        
        // ...
    }
    automaticModule("org.slf4j:slf4j-api", "org.slf4j") {
        mergeJar("org.slf4j:slf4j-ext")
    }
}

Note: The merged Jar will include the first appearance of duplicated files (like the MANIFEST.MF).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].