1- import org.gradle.api.attributes.LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE
2- import org.gradle.api.attributes.java.TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE
31import org.gradle.internal.os.OperatingSystem.*
42
5- plugins {
6- java
7- `java- library`
8- kotlin(" jvm" ) version " 1.3.72"
9- maven
10- // id "org.jetbrains.kotlin.kapt" version "1.3.10"
11- id(" org.jetbrains.dokka" ) version " 0.10.1"
12- id(" com.github.johnrengelman.shadow" ) version " 5.2.0"
13- }
143
154val moduleName = " ${group} .uno_awt"
165
176dependencies {
187
198 implementation(project(" :uno-core" ))
209
21- implementation(kotlin(" stdlib" ))
22- implementation(kotlin(" stdlib-jdk8" ))
23- implementation(kotlin(" reflect" ))
24-
2510 val kx = " com.github.kotlin-graphics"
2611// implementation("$kx:kotlin-unsigned:${findProperty("unsignedVersion")}")
2712 implementation(" $kx :kool:${findProperty(" koolVersion" )} " )
@@ -39,104 +24,9 @@ dependencies {
3924 if (it != " -jawt" )
4025 implementation(" org.lwjgl:lwjgl$it :${findProperty(" lwjglVersion" )} :natives-$lwjglNatives " )
4126 }
42-
43- attributesSchema.attribute(LIBRARY_ELEMENTS_ATTRIBUTE ).compatibilityRules.add(ModularJarCompatibilityRule ::class )
44- components { withModule<ModularKotlinRule >(kotlin(" stdlib" )) }
45- components { withModule<ModularKotlinRule >(kotlin(" stdlib-jdk8" )) }
46-
47- listOf (" runner-junit5" , " assertions-core" , " runner-console" /* , "property"*/ ).forEach {
48- testImplementation(" io.kotest:kotest-$it -jvm:${findProperty(" kotestVersion" )} " )
49- }
50- }
51-
52- java {
53- modularity.inferModulePath.set(true )
54- }
55-
56- tasks {
57- val dokka by getting(org.jetbrains.dokka.gradle.DokkaTask ::class ) {
58- outputFormat = " html"
59- outputDirectory = " $buildDir /dokka"
60- }
61-
62- compileKotlin {
63- kotlinOptions {
64- jvmTarget = " 11"
65- freeCompilerArgs = listOf (" -XXLanguage:+InlineClasses" , " -Xjvm-default=enable" )
66- }
67- sourceCompatibility = " 11"
68- destinationDir = compileJava.get().destinationDir
69- }
70- jar { duplicatesStrategy = DuplicatesStrategy .EXCLUDE }
71-
72- compileTestKotlin {
73- kotlinOptions.jvmTarget = " 11"
74- sourceCompatibility = " 11"
75- }
76- compileJava {
77- println (sourceSets.main.get().output.asPath)
78- // this is needed because we have a separate compile step in this example with the 'module-info.java' is in 'main/java' and the Kotlin code is in 'main/kotlin'
79- options.compilerArgs = listOf (" --patch-module" , " $moduleName =${sourceSets.main.get().output.asPath} " )
80- }
81-
82- withType<Test > { useJUnitPlatform() }
83- }
84-
85- val dokkaJar by tasks.creating(Jar ::class ) {
86- group = JavaBasePlugin .DOCUMENTATION_GROUP
87- description = " Assembles Kotlin docs with Dokka"
88- archiveClassifier.set(" javadoc" )
89- from(tasks.dokka)
90- }
91-
92- val sourceJar = task(" sourceJar" , Jar ::class ) {
93- dependsOn(tasks[" classes" ])
94- archiveClassifier.set(" sources" )
95- from(sourceSets.main.get().allSource)
96- }
97-
98- artifacts {
99- archives(sourceJar)
100- archives(dokkaJar)
10127}
10228
103- // == Add access to the 'modular' variant of kotlin("stdlib"): Put this into a buildSrc plugin and reuse it in all your subprojects
104- configurations.all {
105- attributes.attribute(TARGET_JVM_VERSION_ATTRIBUTE , 11 )
106- val n = name.toLowerCase()
107- if (n.endsWith(" compileclasspath" ) || n.endsWith(" runtimeclasspath" ))
108- attributes.attribute(LIBRARY_ELEMENTS_ATTRIBUTE , objects.named(" modular-jar" ))
109- if (n.endsWith(" compile" ) || n.endsWith(" runtime" ))
110- isCanBeConsumed = false
111- }
112-
113- abstract class ModularJarCompatibilityRule : AttributeCompatibilityRule <LibraryElements > {
114- override fun execute (details : CompatibilityCheckDetails <LibraryElements >): Unit = details.run {
115- if (producerValue?.name == LibraryElements .JAR && consumerValue?.name == " modular-jar" )
116- compatible()
117- }
118- }
119-
120- abstract class ModularKotlinRule : ComponentMetadataRule {
121-
122- @javax.inject.Inject
123- abstract fun getObjects (): ObjectFactory
124-
125- override fun execute (ctx : ComponentMetadataContext ) {
126- val id = ctx.details.id
127- listOf (" compile" , " runtime" ).forEach { baseVariant ->
128- ctx.details.addVariant(" ${baseVariant} Modular" , baseVariant) {
129- attributes {
130- attribute(LIBRARY_ELEMENTS_ATTRIBUTE , getObjects().named(" modular-jar" ))
131- }
132- withFiles {
133- removeAllFiles()
134- addFile(" ${id.name} -${id.version} -modular.jar" )
135- }
136- withDependencies {
137- clear() // 'kotlin-stdlib-common' and 'annotations' are not modules and are also not needed
138- }
139- }
140- }
141- }
29+ tasks.compileJava {
30+ // this is needed because we have a separate compile step in this example with the 'module-info.java' is in 'main/java' and the Kotlin code is in 'main/kotlin'
31+ options.compilerArgs = listOf (" --patch-module" , " $moduleName =${sourceSets.main.get().output.asPath} " )
14232}
0 commit comments