Skip to content

Commit

Permalink
[#1599] Make picocli-codegen artifact a named JPMS module
Browse files Browse the repository at this point in the history
Closes #1599
  • Loading branch information
remkop committed Feb 24, 2022
1 parent 1e0ec5c commit 7a20f0f
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 16 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Picocli 4.7.0 introduced a `sortSynopsis = false` attribute to let the synopsis


## <a name="4.7.0-fixes"></a> Fixed issues
* [#1599] API: The `picocli-codegen` artifact is now a named JPMS module with a `module-info.class`.
* [#1471] API: Provide a programmatic way to configure Picocli's `TraceLevel`. Thanks to [ekinano](https://github.com/ekinano) for raising this.
* [#1125] API: Add parser configuration to allow options to consume values that match subcommand names or option names.
* [#1396][#1401] API: Support generic types in containers (e.g. List, Map). Thanks to [Michał Górniewski](https://github.com/mgorniew) for the pull request.
Expand Down
62 changes: 48 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
dependencies {
classpath "org.asciidoctor:asciidoctor-gradle-jvm:$asciidoctorGradlePluginVersion"
classpath 'org.asciidoctor:asciidoctorj-pdf:1.6.2'
classpath "gradle.plugin.org.beryx:badass-jar:1.2.0"
classpath "org.beryx:badass-jar:2.0.0"
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.1.0'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0"
}
Expand Down Expand Up @@ -105,19 +105,25 @@ allprojects {
}
}

sourceSets.main.java.srcDirs = ['src/main/java', 'src/main/java9']
//sourceSets.main.java.srcDirs = ['src/main/java', 'src/main/java9']
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
if (JavaVersion.current().isJava9Compatible()) {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
}
classpath = files()
}
// doFirst {
// if (JavaVersion.current().isJava9Compatible()) {
// options.compilerArgs = [
// '--module-path', classpath.asPath,
// ]
// }
// classpath = files()
// }
}
moduleConfig {
// copy module-info.class to META-INF/versions/9
multiReleaseVersion = 9
moduleInfoPath = 'src/main/java9/module-info.java'
version = project.version
neverCompileModuleInfo = true
}

jar {
manifest {
attributes 'Specification-Title' : 'picocli',
Expand All @@ -128,10 +134,38 @@ jar {
'Implementation-Version': archiveVersion.get(),
'Main-Class' : 'picocli.AutoComplete'
}
// copy module-info.class to META-INF/versions/9
multiRelease = true
}

configurations {
apiElements {
canBeConsumed = true
canBeResolved = false
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
// not sure why the below is needed, but when building with Java 8, using VERSION_1_5 gives this error:
//
// Could not determine the dependencies of task ':picocli-codegen:compileTestJava'.
//> Could not resolve all task dependencies for configuration ':picocli-codegen:testCompileClasspath'.
// > Could not resolve project :.
// Required by:
// project :picocli-codegen
// > The consumer was configured to find an API of a library compatible with Java 6,
// preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally.
// However we cannot choose between the following variants of project ::
// - apiElements
// - runtimeElements
// All of them match the consumer attributes:
// - Variant 'apiElements' capability info.picocli:picocli:4.7.0-SNAPSHOT declares a runtime of a library compatible with Java 5, packaged as a jar, and its dependencies declared externally:
// - Unmatched attribute:
// - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
// - Variant 'runtimeElements' capability info.picocli:picocli:4.7.0-SNAPSHOT declares a runtime of a library compatible with Java 5, packaged as a jar, and its dependencies declared externally:
// - Unmatched attribute:
// - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, new Integer(JavaVersion.VERSION_1_6.majorVersion))
}
}
}
// jacoco 0.8.2 does not work with Java 13; gradle 4.x has no JavaVersion enum value for Java 12
if (JavaVersion.current().isJava11Compatible()) {
project.logger.lifecycle("skipping jacoco test for Java version ${JavaVersion.current()}")
Expand Down
30 changes: 28 additions & 2 deletions picocli-codegen/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
plugins {
id 'java'
}
apply plugin: "org.beryx.jar"

group 'info.picocli'
description 'Picocli Code Generation - Tools to generate documentation, configuration, source code and other files from a picocli model.'
version "$projectVersion"
ext.moduleName = 'info.picocli.codegen'

// Java 13 cannot compile to target Java 6
if (org.gradle.api.JavaVersion.current().isJava8Compatible() && !org.gradle.api.JavaVersion.current().isJava11Compatible()) {
Expand All @@ -28,15 +30,39 @@ dependencies {
//generateGraalReflectionConfig.dependsOn(compileJava)
//jar.dependsOn(generateGraalReflectionConfig)


//sourceSets.main.java.srcDirs = ['src/main/java', 'src/main/java9']
compileJava {
inputs.property("moduleName", moduleName)
// doFirst {
// logger.info("Java version is " + JavaVersion.current())
// if (JavaVersion.current().isJava9Compatible()) {
// options.compilerArgs = [
// '--module-path', classpath.asPath,
// ]
// }
// // classpath = files()
// classpath = sourceSets.main.runtimeClasspath
// logger.info("options.compilerArgs is " + options.compilerArgs)
// logger.info("classpath is " + classpath.files)
// }
}
moduleConfig {
// copy module-info.class to META-INF/versions/9
multiReleaseVersion = 9
moduleInfoPath = 'src/main/java9/module-info.java'
version = project.version
neverCompileModuleInfo = true
}

jar {
manifest {
attributes 'Specification-Title' : 'Picocli Code Generation',
'Specification-Vendor' : 'Remko Popma',
'Specification-Version' : archiveVersion.get(),
'Implementation-Title' : 'Picocli Code Generation',
'Implementation-Vendor' : 'Remko Popma',
'Implementation-Version': archiveVersion.get(),
'Automatic-Module-Name' : 'info.picocli.codegen'
'Implementation-Version': archiveVersion.get()
}
}

Expand Down
36 changes: 36 additions & 0 deletions picocli-codegen/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2017 Remko Popma
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// When compiling in Gradle, the org.beryx.jar plugin will be able to
// compile this file even with Java versions 8 or older.

// Your IDE may complain that "Modules are not supported at language level '5'",
// and javac may give an error: "java: class, interface or enum expected".
// To resolve this, exclude the 'java9' folder from the sources.
// IntelliJ IDEA:
// File > Project Structure... > Modules > picocli_main > Sources:
// select the 'java9' folder and click 'Mark as: Excluded'.

module info.picocli.codegen {
requires info.picocli;
requires java.compiler;
requires java.logging;

exports picocli.codegen.annotation.processing;
exports picocli.codegen.aot.graalvm;
exports picocli.codegen.aot.graalvm.processor;
exports picocli.codegen.docgen.manpage;
}

0 comments on commit 7a20f0f

Please sign in to comment.