Skip to content

Commit 6d5236a

Browse files
authored
Merge pull request #96 from Jolanrensen/configuration-cache
refactoring to allow for configuration cache
2 parents 6719f75 + 6f465bb commit 6d5236a

5 files changed

Lines changed: 55 additions & 34 deletions

File tree

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.configuration-cache=warn

kodex-example-gradle-project-jvm/build.gradle.kts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import nl.jolanrensen.kodex.defaultProcessors.ARG_DOC_PROCESSOR_LOG_NOT_FOUND
2-
import nl.jolanrensen.kodex.gradle.creatingRunKodexTask
32

43
plugins {
54
kotlin("jvm") // version "2.2.21"
@@ -13,6 +12,7 @@ version = "1.0"
1312

1413
repositories {
1514
mavenCentral()
15+
mavenLocal()
1616
google()
1717
}
1818

@@ -35,6 +35,22 @@ kodex {
3535
preprocess(kotlin.sourceSets.main) {
3636
// optional setup
3737
arguments(ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false)
38+
39+
// Can be enabled if `PluginExtensionTest` has been run to test if extensions work
40+
// processors = listOf(
41+
// COMMENT_DOC_PROCESSOR,
42+
// INCLUDE_DOC_PROCESSOR,
43+
// INCLUDE_FILE_DOC_PROCESSOR,
44+
// ARG_DOC_PROCESSOR,
45+
// SAMPLE_DOC_PROCESSOR,
46+
// EXPORT_AS_HTML_DOC_PROCESSOR,
47+
// REMOVE_ESCAPE_CHARS_PROCESSOR,
48+
// "nl.jolanrensen.extension.Extension",
49+
// )
50+
//
51+
// dependencies {
52+
// plugin("nl.jolanrensen:PluginExtensionTest:0.5.1-SNAPSHOT")
53+
// }
3854
}
3955
}
4056

kodex-gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ tasks.check {
141141
}
142142

143143
tasks.withType<KotlinCompile> {
144+
dependsOn(":kodex-common:shadowJar")
144145
compilerOptions.jvmTarget = JvmTarget.JVM_17
145146
}
146147

kodex-gradle-plugin/src/main/kotlin/nl/jolanrensen/kodex/gradle/CommonKodexTaskProperties.kt

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.gradle.api.Action
1111
import org.gradle.api.NamedDomainObjectContainer
1212
import org.gradle.api.Project
1313
import org.gradle.api.artifacts.Configuration
14-
import org.gradle.api.artifacts.DependencySet
14+
import org.gradle.api.file.FileCollection
1515
import org.gradle.api.model.ObjectFactory
1616
import org.gradle.api.provider.ListProperty
1717
import org.gradle.api.provider.MapProperty
@@ -100,7 +100,7 @@ interface CommonKodexTaskProperties {
100100

101101
/** The classpath of this task. */
102102
@get:Classpath
103-
val classpath: Property<Configuration>
103+
val classpath: Property<FileCollection>
104104

105105
@get:Nested
106106
val exportAsHtml: Property<ExportAsHtmlDsl>
@@ -121,7 +121,24 @@ interface CommonKodexTaskProperties {
121121
* ```
122122
*/
123123
@get:Internal
124-
val dependencies: Property<DependencySetPluginDsl>
124+
val dependencies: DependencySetPluginDsl
125+
get() = object : DependencySetPluginDsl {
126+
/**
127+
* Gets the set of declared dependencies directly contained in this configuration
128+
* (ignoring super configurations).
129+
*
130+
* This method does not resolve the configuration. Therefore, the return value does not include
131+
* transitive dependencies.
132+
*
133+
* @return the set of dependencies
134+
* @see #extendsFrom(Configuration...)
135+
*/
136+
override fun Project.plugin(dependencyNotation: Any) {
137+
(classpath.get() as Configuration).dependencies.add(
138+
dependencies.create(dependencyNotation),
139+
)
140+
}
141+
}
125142

126143
/**
127144
* DSL to add plugin dependencies to the current task. If you want to include a processor from an external library,
@@ -135,7 +152,7 @@ interface CommonKodexTaskProperties {
135152
* }
136153
* ```
137154
*/
138-
fun dependencies(action: Action<DependencySetPluginDsl>): Unit = action.execute(dependencies.get())
155+
fun dependencies(action: Action<DependencySetPluginDsl>): Unit = action.execute(dependencies)
139156

140157
/** like "2.3", uses languageVersion or latest stable if not supplied. */
141158
@get:Input
@@ -201,7 +218,7 @@ interface DependencySetPluginDsl {
201218
*
202219
* @param dependencyNotation Dependency notation
203220
*/
204-
fun plugin(dependencyNotation: Any)
221+
fun Project.plugin(dependencyNotation: Any)
205222
}
206223

207224
fun CommonKodexTaskProperties.applyPropertiesFrom(other: CommonKodexTaskProperties) {
@@ -251,29 +268,6 @@ fun CommonKodexTaskProperties.applyConventions(project: Project, factory: Object
251268
exportAsHtmlInstance.dir.convention(target.map { File(it, "htmlExports") })
252269
exportAsHtmlInstance.outputReadOnly.convention(true)
253270
exportAsHtml.set(exportAsHtmlInstance)
254-
255-
dependencies.set(
256-
object : DependencySetPluginDsl {
257-
/**
258-
* Gets the set of declared dependencies directly contained in this configuration
259-
* (ignoring super configurations).
260-
* <p>
261-
* This method does not resolve the configuration. Therefore, the return value does not include
262-
* transitive dependencies.
263-
*
264-
* @return the set of dependencies
265-
* @see #extendsFrom(Configuration...)
266-
*/
267-
val dependencies: DependencySet
268-
get() = classpath.get().dependencies
269-
270-
override fun plugin(dependencyNotation: Any) {
271-
dependencies.add(
272-
project.dependencies.create(dependencyNotation),
273-
)
274-
}
275-
},
276-
)
277271
}
278272

279273
internal fun Project.maybeCreateRuntimeConfiguration(): Configuration =

kodex-gradle-plugin/src/main/kotlin/nl/jolanrensen/kodex/gradle/RunKodexTask.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import org.gradle.api.provider.ListProperty
1212
import org.gradle.api.provider.Property
1313
import org.gradle.api.tasks.Input
1414
import org.gradle.api.tasks.InputFiles
15+
import org.gradle.api.tasks.Internal
1516
import org.gradle.api.tasks.OutputFiles
1617
import org.gradle.api.tasks.TaskAction
18+
import org.gradle.kotlin.dsl.listProperty
1719
import org.gradle.kotlin.dsl.property
1820
import org.gradle.workers.WorkerExecutor
1921
import java.io.File
@@ -27,8 +29,10 @@ private val log = KotlinLogging.logger { }
2729
*/
2830
abstract class RunKodexTask
2931
@Inject
30-
constructor(factory: ObjectFactory, project: Project) :
31-
DefaultTask(),
32+
constructor(
33+
@get:Internal val factory: ObjectFactory,
34+
project: Project,
35+
) : DefaultTask(),
3236
CommonKodexTaskProperties {
3337

3438
init {
@@ -72,13 +76,18 @@ abstract class RunKodexTask
7276
fun calculateTargets(): FileCollection {
7377
val relativeSources = sources.get().map { it.relativeTo(baseDir.get()) }
7478
val target = target.get()
75-
return project.files(relativeSources.map { File(target, it.path) })
79+
return factory.fileCollection().from(relativeSources.map { File(target, it.path) })
7680
}
7781

7882
/** Used by the task to execute [RunKodexGradleAction]. */
7983
@get:Inject
8084
abstract val workerExecutor: WorkerExecutor
8185

86+
@get:InputFiles
87+
internal val projectClassPath: ListProperty<File> = factory
88+
.listProperty<File>()
89+
.convention(project.files().toList())
90+
8291
@Deprecated(
8392
"This notation is no longer needed.",
8493
replaceWith = ReplaceWith("block()"),
@@ -108,7 +117,7 @@ abstract class RunKodexTask
108117

109118
val sourceRoots = sources.get()
110119
val target = target.get()
111-
val runtime = classpath.get().resolve()
120+
val runtime = classpath.get() // .resolve()
112121
val processors = processors.get()
113122

114123
(targets as ConfigurableFileCollection).setFrom(calculateTargets())
@@ -128,7 +137,7 @@ abstract class RunKodexTask
128137
languageVersion = languageVersion.getOrNull(),
129138
apiVersion = apiVersion.getOrNull(),
130139
analysisPlatform = analysisPlatform.getOrNull(),
131-
classpath = project.files().toList(),
140+
classpath = projectClassPath.get(),
132141
)
133142

134143
val workQueue = workerExecutor.classLoaderIsolation {

0 commit comments

Comments
 (0)