Browse Source

Build: Stub invisible modules to avoid compiler warnings

Some modules explicitly export only to darklaf.core, because
they are implementation modules. To avoid compiler warnings
we stub the module definition.
pull/307/head
Jannis Weis 3 years ago
parent
commit
59ca3502c8
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 37
      buildSrc/src/main/kotlin/ModuleInfoCompilePlugin.kt
  2. 1
      compatibility/build.gradle.kts
  3. 6
      macos/build.gradle.kts
  4. 4
      windows/build.gradle.kts

37
buildSrc/src/main/kotlin/ModuleInfoCompilePlugin.kt

@ -14,6 +14,8 @@ import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.registering
import org.gradle.kotlin.dsl.withType
import org.gradle.process.JavaForkOptions
import java.io.File
import java.nio.file.Files
import java.util.regex.Pattern
class ExecParameters(
@ -35,6 +37,9 @@ open class ModuleInfoExtension {
lateinit var moduleName: String
val execParameters = ExecParameters()
internal val stubbedModules = mutableListOf<String>()
fun stubModule(moduleName: String) = stubbedModules.add(moduleName)
fun modularExec(action: ExecParameters.() -> Unit) = execParameters.action()
}
@ -47,7 +52,8 @@ class ModuleInfoCompilePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run {
val infoExtension = target.extensions.create("moduleInfo", ModuleInfoExtension::class.java)
if (!JavaVersion.current().isJava9Compatible
|| project.findProperty("skipModuleInfo") in listOf("", "true")) return@run
|| project.findProperty("skipModuleInfo") in listOf("", "true")
) return@run
val moduleInfoFile = file("src/main/module/module-info.java")
if (moduleInfoFile.exists()) {
@ -73,16 +79,43 @@ class ModuleInfoCompilePlugin : Plugin<Project> {
}
private fun Project.setupModuleInfoCompilation(infoExtension: ModuleInfoExtension) {
val stubOutputDir = buildDir.resolve("generated/moduleInfoStubs")
fun String.stubModuleInfoPath() = stubOutputDir.resolve("$this/module-info.java")
val createModuleStubs by tasks.registering(JavaCompile::class) {
stubOutputDir.deleteRecursively()
Files.createDirectories(stubOutputDir.toPath())
infoExtension.stubbedModules.forEach {
source(it.stubModuleInfoPath().also { file ->
file.parentFile.mkdirs()
file.writeText("module $it {}")
})
}
classpath = files()
options.compilerArgs.addAll(listOf(
"--release", infoExtension.version.majorVersion,
"--module-source-path", stubOutputDir.absolutePath
))
destinationDirectory.set(buildDir.resolve("classes/moduleStubs"))
}
val compileJava = tasks.named<JavaCompile>("compileJava")
val compileModuleInfoJava by tasks.registering(JavaCompile::class) {
dependsOn(createModuleStubs)
val javaCompile = compileJava.get()
classpath = files()
source("src/main/module/module-info.java")
source(javaCompile.source)
destinationDirectory.set(buildDir.resolve("classes/module"))
check(infoExtension.version.isJava9Compatible)
options.compilerArgs.addAll(listOf("--module-path", javaCompile.classpath.asPath))
val separator = "${File.pathSeparatorChar}"
val modulePath = javaCompile.classpath.asPath + separator + infoExtension.stubbedModules
.joinToString(separator) { "${stubOutputDir.absolutePath}/$it/$it.jar" }
options.compilerArgs.addAll(listOf("--module-path", modulePath))
if (infoExtension.extraArgs.isNotEmpty()) {
options.compilerArgs.addAll(infoExtension.extraArgs)
sourceCompatibility = infoExtension.version.majorVersion

1
compatibility/build.gradle.kts

@ -12,6 +12,7 @@ configure<ModuleInfoExtension> {
extraArgs = listOf(
"--add-exports", "java.desktop/sun.awt=darklaf.compatibility"
)
stubModule("darklaf.core")
}
dependencies {

6
macos/build.gradle.kts

@ -1,5 +1,3 @@
plugins {
java
`module-info-compile`
@ -10,6 +8,10 @@ plugins {
`apple-m1-toolchain`
}
moduleInfo {
stubModule("darklaf.core")
}
val jnfConfig: Configuration by configurations.creating {
attributes {
attribute(Attribute.of("dev.nokee.architecture", String::class.java), "arm64")

4
windows/build.gradle.kts

@ -7,6 +7,10 @@ plugins {
`use-prebuilt-binaries`
}
moduleInfo {
stubModule("darklaf.core")
}
library {
dependencies {
jvmImplementation(projects.darklafNativeUtils)

Loading…
Cancel
Save