-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdc7eb9
commit ea8d2c0
Showing
3 changed files
with
27 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
|
||
plugins { | ||
id("kotlin") | ||
id("org.moditect.gradleplugin") | ||
} | ||
|
||
moditect { | ||
// Generate a multi-release jar, the module descriptor will be located at META-INF/versions/9/module-info.class | ||
addMainModuleInfo { | ||
jvmVersion.set("9") | ||
overwriteExistingFiles.set(true) | ||
module { | ||
moduleInfoFile = file("src/main/moditect/module-info.java") | ||
val moditect by tasks.registering { | ||
doLast { | ||
// Generate a multi-release modulized jar, module descriptor position: META-INF/versions/9/module-info.class | ||
val inputJar = tasks.jar.flatMap { it.archiveFile }.map { it.asFile.toPath() }.get() | ||
val outputDir = file("build/moditect").apply { mkdirs() }.toPath() | ||
val moduleInfo = file("src/main/moditect/module-info.java").readText() | ||
val version = project.version.toString() | ||
org.moditect.commands.AddModuleInfo(moduleInfo, null, version, inputJar, outputDir, "9", true).run() | ||
|
||
// Replace the original jar with the modulized jar. | ||
copy { | ||
from(outputDir.resolve(inputJar.fileName)) | ||
into(inputJar.parent) | ||
} | ||
} | ||
} | ||
|
||
// Let kotlin compiler know the module descriptor. | ||
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) { | ||
sourceSets.main { | ||
kotlin.srcDir("src/main/moditect") | ||
} | ||
tasks { | ||
moditect { | ||
dependsOn(jar) | ||
} | ||
jar { | ||
finalizedBy(moditect) | ||
} | ||
} | ||
|
||
// Workaround to avoid circular task dependencies, see https://github.com/moditect/moditect-gradle-plugin/issues/14 | ||
afterEvaluate { | ||
val compileJava = tasks.compileJava.get() | ||
val addDependenciesModuleInfo = tasks.addDependenciesModuleInfo.get() | ||
compileJava.setDependsOn(compileJava.dependsOn - addDependenciesModuleInfo) | ||
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) { | ||
// Let kotlin compiler know the module descriptor. | ||
sourceSets.main { | ||
kotlin.srcDir("src/main/moditect") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters