1
+ import org.gradle.api.attributes.LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE
2
+ import org.gradle.api.attributes.java.TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE
3
+ import org.gradle.internal.os.OperatingSystem.*
4
+ import org.jetbrains.dokka.gradle.DokkaTask
5
+
6
+ plugins {
7
+ java
8
+ kotlin(" jvm" ) version " 1.3.72"
9
+ maven
10
+ id(" org.jetbrains.dokka" ) version " 0.10.1"
11
+ id(" com.github.johnrengelman.shadow" ).version(" 5.2.0" )
12
+ }
13
+
14
+ val group = " com.github.kotlin_graphics"
15
+ val moduleName = " $group .gli"
16
+ val kotestVersion = " 4.0.5"
17
+
18
+
19
+ val kx = " com.github.kotlin-graphics"
20
+ val unsignedVersion = " 0af6fae4"
21
+ val koolVersion = " 3962a0be"
22
+ val glmVersion = " 5b0f3461"
23
+ val lwjglVersion = " 3.2.3"
24
+ val lwjglNatives = when (current()) {
25
+ WINDOWS -> " windows"
26
+ LINUX -> " linux"
27
+ else -> " macos"
28
+ }
29
+
30
+ repositories {
31
+ mavenCentral()
32
+ jcenter()
33
+ maven { url = uri(" https://jitpack.io" ) }
34
+ }
35
+
36
+ dependencies {
37
+ implementation(kotlin(" stdlib" ))
38
+ implementation(kotlin(" stdlib-jdk8" ))
39
+
40
+ implementation(" $kx :kotlin-unsigned:$unsignedVersion " )
41
+ implementation(" $kx :kool:$koolVersion " )
42
+ implementation(" $kx :glm:$glmVersion " )
43
+
44
+ // https://mvnrepository.com/artifact/com.twelvemonkeys.imageio/imageio-core
45
+ listOf (" " , /* "-batik",*/ " -bmp" , " -core" , " -icns" , " -iff" , " -jpeg" , " -metadata" , " -pcx" , " -pdf" , " -pict" , " -pnm" ,
46
+ " -psd" , " -sgi" , " -tga" , " -thumbsdb" , " -tiff" /* , "-reference", "-clippath", "-hdr"*/ ).forEach {
47
+ implementation(" com.twelvemonkeys.imageio:imageio$it :3.5" )
48
+ }
49
+ // https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-transcoder
50
+ // implementation "org.apache.xmlgraphics:batik-transcoder:1.12"
51
+
52
+ listOf (" " , " -jemalloc" , " -opengl" ).forEach {
53
+ implementation(" org.lwjgl:lwjgl$it :$lwjglVersion " )
54
+ implementation(" org.lwjgl:lwjgl$it :$lwjglVersion :natives-$lwjglNatives " )
55
+ }
56
+
57
+ attributesSchema.attribute(LIBRARY_ELEMENTS_ATTRIBUTE ).compatibilityRules.add(ModularJarCompatibilityRule ::class )
58
+ components { withModule<ModularKotlinRule >(kotlin(" stdlib" )) }
59
+ components { withModule<ModularKotlinRule >(kotlin(" stdlib-jdk8" )) }
60
+
61
+ listOf (" runner-junit5" , " assertions-core" , " runner-console" /* , "property"*/ ).forEach {
62
+ testImplementation(" io.kotest:kotest-$it -jvm:$kotestVersion " )
63
+ }
64
+ }
65
+
66
+ java {
67
+ modularity.inferModulePath.set(true )
68
+ }
69
+
70
+ tasks {
71
+ val dokka by getting(DokkaTask ::class ) {
72
+ outputFormat = " html"
73
+ outputDirectory = " $buildDir /dokka"
74
+ }
75
+
76
+ compileKotlin {
77
+ kotlinOptions {
78
+ jvmTarget = " 11"
79
+ freeCompilerArgs = listOf (" -XXLanguage:+InlineClasses" )
80
+ }
81
+ sourceCompatibility = " 11"
82
+ }
83
+
84
+ compileTestKotlin {
85
+ kotlinOptions.jvmTarget = " 11"
86
+ sourceCompatibility = " 11"
87
+ }
88
+
89
+ compileJava {
90
+ // 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'
91
+ options.compilerArgs = listOf (" --patch-module" , " $moduleName =${sourceSets.main.get().output.asPath} " )
92
+ }
93
+
94
+ withType<Test > { useJUnitPlatform() }
95
+ }
96
+
97
+ val dokkaJar by tasks.creating(Jar ::class ) {
98
+ group = JavaBasePlugin .DOCUMENTATION_GROUP
99
+ description = " Assembles Kotlin docs with Dokka"
100
+ archiveClassifier.set(" javadoc" )
101
+ from(tasks.dokka)
102
+ }
103
+
104
+ val sourceJar = task(" sourceJar" , Jar ::class ) {
105
+ dependsOn(tasks[" classes" ])
106
+ archiveClassifier.set(" sources" )
107
+ from(sourceSets.main.get().allSource)
108
+ }
109
+
110
+ artifacts {
111
+ archives(sourceJar)
112
+ archives(dokkaJar)
113
+ }
114
+
115
+ // == Add access to the 'modular' variant of kotlin("stdlib"): Put this into a buildSrc plugin and reuse it in all your subprojects
116
+ configurations.all {
117
+ attributes.attribute(TARGET_JVM_VERSION_ATTRIBUTE , 11 )
118
+ val n = name.toLowerCase()
119
+ if (n.endsWith(" compileclasspath" ) || n.endsWith(" runtimeclasspath" ))
120
+ attributes.attribute(LIBRARY_ELEMENTS_ATTRIBUTE , objects.named(" modular-jar" ))
121
+ if (n.endsWith(" compile" ) || n.endsWith(" runtime" ))
122
+ isCanBeConsumed = false
123
+ }
124
+
125
+ abstract class ModularJarCompatibilityRule : AttributeCompatibilityRule <LibraryElements > {
126
+ override fun execute (details : CompatibilityCheckDetails <LibraryElements >): Unit = details.run {
127
+ if (producerValue?.name == LibraryElements .JAR && consumerValue?.name == " modular-jar" )
128
+ compatible()
129
+ }
130
+ }
131
+
132
+ abstract class ModularKotlinRule : ComponentMetadataRule {
133
+
134
+ @javax.inject.Inject
135
+ abstract fun getObjects (): ObjectFactory
136
+
137
+ override fun execute (ctx : ComponentMetadataContext ) {
138
+ val id = ctx.details.id
139
+ listOf (" compile" , " runtime" ).forEach { baseVariant ->
140
+ ctx.details.addVariant(" ${baseVariant} Modular" , baseVariant) {
141
+ attributes {
142
+ attribute(LIBRARY_ELEMENTS_ATTRIBUTE , getObjects().named(" modular-jar" ))
143
+ }
144
+ withFiles {
145
+ removeAllFiles()
146
+ addFile(" ${id.name} -${id.version} -modular.jar" )
147
+ }
148
+ withDependencies {
149
+ clear() // 'kotlin-stdlib-common' and 'annotations' are not modules and are also not needed
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
0 commit comments