|
1 | 1 |
|
2 | 2 | plugins {
|
3 | 3 | id("kotlin")
|
4 |
| - id("org.moditect.gradleplugin") |
5 | 4 | }
|
6 | 5 |
|
7 |
| -moditect { |
8 |
| - // Generate a multi-release jar, the module descriptor will be located at META-INF/versions/9/module-info.class |
9 |
| - addMainModuleInfo { |
10 |
| - jvmVersion.set("9") |
11 |
| - overwriteExistingFiles.set(true) |
12 |
| - module { |
13 |
| - moduleInfoFile = file("src/main/moditect/module-info.java") |
| 6 | +val moditect by tasks.registering { |
| 7 | + doLast { |
| 8 | + // Generate a multi-release modulized jar, module descriptor position: META-INF/versions/9/module-info.class |
| 9 | + val inputJar = tasks.jar.flatMap { it.archiveFile }.map { it.asFile.toPath() }.get() |
| 10 | + val outputDir = file("build/moditect").apply { mkdirs() }.toPath() |
| 11 | + val moduleInfo = file("src/main/moditect/module-info.java").readText() |
| 12 | + val version = project.version.toString() |
| 13 | + org.moditect.commands.AddModuleInfo(moduleInfo, null, version, inputJar, outputDir, "9", true).run() |
| 14 | + |
| 15 | + // Replace the original jar with the modulized jar. |
| 16 | + copy { |
| 17 | + from(outputDir.resolve(inputJar.fileName)) |
| 18 | + into(inputJar.parent) |
14 | 19 | }
|
15 | 20 | }
|
| 21 | +} |
16 | 22 |
|
17 |
| - // Let kotlin compiler know the module descriptor. |
18 |
| - if (JavaVersion.current() >= JavaVersion.VERSION_1_9) { |
19 |
| - sourceSets.main { |
20 |
| - kotlin.srcDir("src/main/moditect") |
21 |
| - } |
| 23 | +tasks { |
| 24 | + moditect { |
| 25 | + dependsOn(jar) |
22 | 26 | }
|
| 27 | + jar { |
| 28 | + finalizedBy(moditect) |
| 29 | + } |
| 30 | +} |
23 | 31 |
|
24 |
| - // Workaround to avoid circular task dependencies, see https://github.com/moditect/moditect-gradle-plugin/issues/14 |
25 |
| - afterEvaluate { |
26 |
| - val compileJava = tasks.compileJava.get() |
27 |
| - val addDependenciesModuleInfo = tasks.addDependenciesModuleInfo.get() |
28 |
| - compileJava.setDependsOn(compileJava.dependsOn - addDependenciesModuleInfo) |
| 32 | +if (JavaVersion.current() >= JavaVersion.VERSION_1_9) { |
| 33 | + // Let kotlin compiler know the module descriptor. |
| 34 | + sourceSets.main { |
| 35 | + kotlin.srcDir("src/main/moditect") |
29 | 36 | }
|
30 | 37 | }
|
0 commit comments