Skip to content

Commit

Permalink
issue #3: Set module version
Browse files Browse the repository at this point in the history
  • Loading branch information
siordache committed Oct 28, 2021
1 parent 0c03aa5 commit b9671a7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
14 changes: 14 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ jar {
}
----

==== Module version

By default, the plugin sets the module version using the value of your project version. You can provide a different value by setting the `version` property in the `modularity` extension of the `jar` task:

[source,groovy]
----
jar {
...
modularity {
version = '2.3.4'
}
...
}
----

=== Examples

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
badassJarVersionMajor = 2
badassJarVersionMinor = 0
badassJarVersionPatch = 0
badassJarVersionLabel = rc-1
badassJarReleaseBuild = true
badassJarVersionLabel = rc-2
badassJarReleaseBuild = false
18 changes: 13 additions & 5 deletions src/main/groovy/org/beryx/jar/BadassJarPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ class BadassJarPlugin implements Plugin<Project> {
}
}
if(moduleInfoFile) {
createModuleDescriptor(project, moduleInfoFile.text, jarTask, project.sourceSets.main.java.outputDir)
createModuleDescriptor(project, moduleInfoFile.text, jarTask, project.sourceSets.main.java.destinationDirectory.asFile.get())
}
}
} else {
LOGGER.info "badass-jar: module-info.class will be created by the compiler because compatibility >= 9"
if(jarModularity.multiRelease) {
if(jarModularity.multiRelease.getOrElse(false)) {
LOGGER.warn("badass-jar: ignoring multiRelease because compatibility >= 9")
}
String moduleVersion = jarModularity.versionOrDefault
if(moduleVersion) {
def versionArgs = ['--module-version', moduleVersion]
LOGGER.debug "badass-jar: using versionArgs: $versionArgs"
project.tasks.compileJava.options.compilerArgs.addAll versionArgs
}
if(moduleInfoPath) {
File moduleInfoFile = project.file(moduleInfoPath)
if(!moduleInfoFile.file) throw new GradleException("$moduleInfoFile.absolutePath not available")
Expand All @@ -84,11 +90,13 @@ class BadassJarPlugin implements Plugin<Project> {
}

File createModuleDescriptor(Project project, String moduleInfoSource, Jar jarTask, File targetBaseDir) {
JarModularityExtension jarModularity = jarTask.getExtensions().getByName("modularity")
ModuleDeclaration module = ModuleInfoCompiler.parseModuleInfo(moduleInfoSource);
byte[] clazz = ModuleInfoCompiler.compileModuleInfo( module, null, null);
String version = jarModularity.versionOrDefault
LOGGER.debug "badass-jar: Setting module version to $version"
byte[] clazz = ModuleInfoCompiler.compileModuleInfo( module, null, version);
LOGGER.debug "badass-jar: Module info compiled: $clazz.length bytes"
JarModularityExtension jarModularity = jarTask.getExtensions().getByName("modularity")
boolean multiRelease = jarModularity.multiRelease.get()
boolean multiRelease = jarModularity.multiRelease.getOrElse(false)
LOGGER.debug "badass-jar: multiRelease = $multiRelease"
if(multiRelease) {
jarTask.manifest {
Expand Down
7 changes: 7 additions & 0 deletions src/main/groovy/org/beryx/jar/JarModularityExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JarModularityExtension {
private final Project project
final Property<String> moduleInfoPath
final Property<Boolean> multiRelease
final Property<String> version

JarModularityExtension(Project project) {
this.project = project;
Expand All @@ -31,5 +32,11 @@ class JarModularityExtension {

multiRelease = project.objects.property(Boolean)
multiRelease.set(true)

version = project.objects.property(String)
}

String getVersionOrDefault() {
version.getOrElse(project.version as String)
}
}

0 comments on commit b9671a7

Please sign in to comment.