@@ -16,18 +16,23 @@ import org.jetbrains.kotlin.gradle.*
16
16
import org.jetbrains.kotlin.gradle.dsl.*
17
17
import org.jetbrains.kotlin.gradle.plugin.*
18
18
import org.jetbrains.kotlin.gradle.plugin.mpp.*
19
- import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.*
20
19
import org.jetbrains.kotlin.gradle.targets.jvm.*
21
20
import org.jetbrains.kotlin.gradle.tasks.*
22
21
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23
22
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
24
- import org.jetbrains.kotlin.gradle.utils.*
25
23
import org.jetbrains.kotlin.tooling.core.*
26
24
import java.io.*
27
25
import kotlin.reflect.*
28
26
import kotlin.reflect.full.*
29
27
30
28
object Java9Modularity {
29
+ private val KotlinProjectExtension .targets: Iterable <KotlinTarget >
30
+ get() = when (this ) {
31
+ is KotlinSingleTargetExtension <* > -> listOf (this .target)
32
+ is KotlinMultiplatformExtension -> targets
33
+ else -> error(" Unexpected 'kotlin' extension $this " )
34
+ }
35
+
31
36
32
37
@JvmStatic
33
38
@JvmOverloads
@@ -50,16 +55,19 @@ object Java9Modularity {
50
55
}
51
56
52
57
target.compilations.forEach { compilation ->
53
- val compileKotlinTask = compilation.compileKotlinTask as KotlinCompile
58
+ @Suppress(" UNCHECKED_CAST" )
59
+ val compileKotlinTask = compilation.compileTaskProvider as TaskProvider <KotlinCompile >
54
60
val defaultSourceSet = compilation.defaultSourceSet
55
61
56
62
// derive the names of the source set and compile module task
57
63
val sourceSetName = defaultSourceSet.name + " Module"
58
64
59
65
kotlin.sourceSets.create(sourceSetName) {
60
66
val sourceFile = this .kotlin.find { it.name == " module-info.java" }
61
- val targetDirectory = compileKotlinTask.destinationDirectory.map {
62
- it.dir(" ../${it.asFile.name} Module" )
67
+ val targetDirectory = compileKotlinTask.flatMap { task ->
68
+ task.destinationDirectory.map {
69
+ it.dir(" ../${it.asFile.name} Module" )
70
+ }
63
71
}
64
72
65
73
// only configure the compilation if necessary
@@ -110,7 +118,7 @@ object Java9Modularity {
110
118
* but it currently won't compile to a module-info.class file.
111
119
*/
112
120
private fun Project.registerVerifyModuleTask (
113
- compileTask : KotlinCompile ,
121
+ compileTask : TaskProvider < KotlinCompile > ,
114
122
sourceFile : File
115
123
): TaskProvider <out KotlinJvmCompile > {
116
124
apply<KotlinApiPlugin >()
@@ -120,28 +128,28 @@ object Java9Modularity {
120
128
val kotlinApiPlugin = plugins.getPlugin(KotlinApiPlugin ::class )
121
129
val verifyModuleTask = kotlinApiPlugin.registerKotlinJvmCompileTask(
122
130
verifyModuleTaskName,
123
- compileTask.compilerOptions.moduleName.get()
131
+ compilerOptions = compileTask.get().compilerOptions,
132
+ explicitApiMode = provider { ExplicitApiMode .Disabled }
124
133
)
125
134
verifyModuleTask {
126
135
group = VERIFICATION_GROUP
127
136
description = " Verify Kotlin sources for JPMS problems"
128
- libraries.from(compileTask.libraries)
129
- source(compileTask.sources)
130
- source(compileTask.javaSources)
137
+ libraries.from(compileTask.map { it. libraries } )
138
+ source(compileTask.map { it. sources } )
139
+ source(compileTask.map { it. javaSources } )
131
140
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
132
- @Suppress(" INVISIBLE_MEMBER" )
133
- source(compileTask.scriptSources)
141
+ source(compileTask.map {
142
+ @Suppress(" INVISIBLE_MEMBER" )
143
+ it.scriptSources
144
+ })
134
145
source(sourceFile)
135
146
destinationDirectory.set(temporaryDir)
136
- multiPlatformEnabled.set(compileTask.multiPlatformEnabled)
147
+ multiPlatformEnabled.set(compileTask.get(). multiPlatformEnabled)
137
148
compilerOptions {
138
149
jvmTarget.set(JvmTarget .JVM_9 )
139
- // To support LV override when set in aggregate builds
140
- languageVersion.set(compileTask.compilerOptions.languageVersion)
141
150
freeCompilerArgs.addAll(
142
151
listOf (" -Xjdk-release=9" , " -Xsuppress-version-warnings" , " -Xexpect-actual-classes" )
143
152
)
144
- optIn.addAll(compileTask.compilerOptions.optIn)
145
153
}
146
154
// work-around for https://youtrack.jetbrains.com/issue/KT-60583
147
155
inputs.files(
@@ -162,18 +170,21 @@ object Java9Modularity {
162
170
.declaredMemberProperties
163
171
.find { it.name == " ownModuleName" }
164
172
?.get(this ) as ? Property <String >
165
- ownModuleNameProp?.set(compileTask.compilerOptions.moduleName)
173
+ ownModuleNameProp?.set(compileTask.flatMap { it. compilerOptions.moduleName} )
166
174
}
167
175
168
176
val taskKotlinLanguageVersion = compilerOptions.languageVersion.orElse(KotlinVersion .DEFAULT )
169
177
@OptIn(InternalKotlinGradlePluginApi ::class )
170
178
if (taskKotlinLanguageVersion.get() < KotlinVersion .KOTLIN_2_0 ) {
171
179
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
172
180
@Suppress(" INVISIBLE_MEMBER" )
173
- commonSourceSet.from(compileTask.commonSourceSet)
181
+ commonSourceSet.from(compileTask.map {
182
+ @Suppress(" INVISIBLE_MEMBER" )
183
+ it.commonSourceSet
184
+ })
174
185
} else {
175
- multiplatformStructure.refinesEdges.set(compileTask.multiplatformStructure.refinesEdges)
176
- multiplatformStructure.fragments.set(compileTask.multiplatformStructure.fragments)
186
+ multiplatformStructure.refinesEdges.set(compileTask.flatMap { it. multiplatformStructure.refinesEdges } )
187
+ multiplatformStructure.fragments.set(compileTask.flatMap { it. multiplatformStructure.fragments } )
177
188
}
178
189
// part of work-around for https://youtrack.jetbrains.com/issue/KT-60541
179
190
// and work-around for https://youtrack.jetbrains.com/issue/KT-60582
@@ -183,7 +194,7 @@ object Java9Modularity {
183
194
}
184
195
185
196
private fun Project.registerCompileModuleTask (
186
- compileTask : KotlinCompile ,
197
+ compileTask : TaskProvider < KotlinCompile > ,
187
198
sourceFile : File ,
188
199
targetDirectory : Provider <out Directory >
189
200
) = tasks.register(" ${compileTask.name} Module" , JavaCompile ::class ) {
@@ -203,10 +214,12 @@ object Java9Modularity {
203
214
204
215
options.compilerArgumentProviders.add(object : CommandLineArgumentProvider {
205
216
@get:CompileClasspath
206
- val compileClasspath = compileTask.libraries
217
+ val compileClasspath = objects.fileCollection().from(
218
+ compileTask.map { it.libraries }
219
+ )
207
220
208
221
@get:CompileClasspath
209
- val compiledClasses = compileTask.destinationDirectory
222
+ val compiledClasses = compileTask.flatMap { it. destinationDirectory }
210
223
211
224
@get:Input
212
225
val moduleName = sourceFile
0 commit comments