Skip to content

Commit ba5fe1b

Browse files
committed
Extract more stuff to a 'base' plugin
1 parent b1a8136 commit ba5fe1b

22 files changed

+130
-153
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.assemble
2+
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.jar
3+
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.sourceSets
4+
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.test
5+
import org.gradle.api.tasks.SourceSetContainer
6+
import org.gradle.api.tasks.testing.Test
7+
import org.gradle.kotlin.dsl.configure
8+
import org.gradle.kotlin.dsl.creating
9+
import org.gradle.kotlin.dsl.get
10+
import org.gradle.kotlin.dsl.getValue
11+
import org.gradle.kotlin.dsl.invoke
12+
import org.gradle.kotlin.dsl.withType
13+
import org.jetbrains.dokka.gradle.DokkaTask
14+
15+
/**
16+
* Plugin for base build setup of faker modules with kotlin
17+
*/
18+
19+
plugins {
20+
base
21+
kotlin("jvm")
22+
id("org.jetbrains.dokka")
23+
}
24+
25+
configurations {
26+
create("integrationImplementation") { extendsFrom(configurations.getByName("testImplementation")) }
27+
create("integrationRuntimeOnly") {
28+
if (isShadow) {
29+
extendsFrom(
30+
configurations.getByName("testRuntimeOnly"),
31+
configurations.getByName("shadow"),
32+
)
33+
} else {
34+
extendsFrom(configurations.getByName("testRuntimeOnly"))
35+
}
36+
}
37+
}
38+
39+
// configure sourceSets as extension since it's not available here as `sourceSets` is an extension on `Project`
40+
// https://docs.gradle.org/current/userguide/kotlin_dsl.html#project_extensions_and_conventions
41+
configure<SourceSetContainer> {
42+
create("integration") {
43+
resources.srcDir("src/integration/resources")
44+
compileClasspath += main.get().compileClasspath + test.get().compileClasspath
45+
runtimeClasspath += main.get().runtimeClasspath + test.get().runtimeClasspath
46+
}
47+
main {
48+
resources {
49+
this.srcDir("build/generated/src/main/resources")
50+
}
51+
}
52+
}
53+
54+
val integrationTest by tasks.creating(Test::class) {
55+
testClassesDirs = sourceSets["integration"].output.classesDirs
56+
classpath = sourceSets["integration"].runtimeClasspath
57+
dependsOn(tasks.test)
58+
}
59+
60+
tasks.withType<Jar> {
61+
archiveBaseName.set(fullName)
62+
63+
manifest {
64+
attributes(
65+
mapOf(
66+
"Implementation-Title" to fullName,
67+
"Implementation-Version" to project.version,
68+
/*
69+
* We can't add this here because this resolves the configuration,
70+
* after which it effectively becomes read-only and we'll get an error
71+
* Cannot change dependencies of dependency configuration ':core:implementation' after it has been included in dependency resolution
72+
* if we try to add more dependencies in the module's build.gradle file directly
73+
*/
74+
// "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name }
75+
)
76+
)
77+
}
78+
}
79+
80+
tasks {
81+
assemble {
82+
dependsOn(jar)
83+
}
84+
}
85+
86+
tasks {
87+
jar {
88+
dependsOn(integrationTest)
89+
}
90+
assemble {
91+
dependsOn(integrationTest)
92+
}
93+
}
94+
95+
tasks.withType<DokkaTask>().configureEach {
96+
onlyIf("Not dev") { !isDev.get() }
97+
onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() }
98+
}
Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,13 @@
1-
import org.jetbrains.dokka.gradle.DokkaTask
1+
/**
2+
* Plugin for :extension:* modules
3+
*/
24

35
plugins {
4-
base
5-
kotlin("jvm")
6-
id("org.jetbrains.dokka")
6+
id("faker-base-conventions")
77
id("faker-pub-conventions")
88
}
99

10-
configurations {
11-
create("integrationImplementation") { extendsFrom(configurations.getByName("testImplementation")) }
12-
create("integrationRuntimeOnly") {
13-
extendsFrom(
14-
configurations.getByName("testRuntimeOnly"),
15-
)
16-
}
17-
}
18-
19-
// configure sourceSets as extension since it's not available here as `sourceSets` is an extension on `Project`
20-
// https://docs.gradle.org/current/userguide/kotlin_dsl.html#project_extensions_and_conventions
21-
configure<SourceSetContainer> {
22-
create("integration") {
23-
resources.srcDir("src/integration/resources")
24-
compileClasspath += main.get().compileClasspath + test.get().compileClasspath
25-
runtimeClasspath += main.get().runtimeClasspath + test.get().runtimeClasspath
26-
}
27-
main {
28-
resources {
29-
this.srcDir("build/generated/src/main/resources")
30-
}
31-
}
32-
}
33-
3410
dependencies {
3511
val implementation by configurations
3612
implementation(libs.bundles.kotlin)
3713
}
38-
39-
val integrationTest by tasks.creating(Test::class) {
40-
testClassesDirs = sourceSets["integration"].output.classesDirs
41-
classpath = sourceSets["integration"].runtimeClasspath
42-
dependsOn(tasks.test)
43-
}
44-
45-
tasks.withType<Jar> {
46-
archiveBaseName.set(fullName)
47-
48-
manifest {
49-
attributes(
50-
mapOf(
51-
"Implementation-Title" to fullName,
52-
"Implementation-Version" to project.version,
53-
/*
54-
* We can't add this here because this resolves the configuration,
55-
* after which it effectively becomes read-only and we'll get an error
56-
* Cannot change dependencies of dependency configuration ':core:implementation' after it has been included in dependency resolution
57-
* if we try to add more dependencies in the module's build.gradle file directly
58-
*/
59-
// "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name }
60-
)
61-
)
62-
}
63-
64-
dependsOn(integrationTest)
65-
}
66-
67-
artifacts {
68-
archives(sourcesJar)
69-
archives(dokkaJavadocJar)
70-
}
71-
72-
tasks {
73-
assemble {
74-
dependsOn(integrationTest)
75-
dependsOn(jar)
76-
}
77-
}
78-
79-
tasks.withType<DokkaTask>().configureEach {
80-
onlyIf("Not dev") { !isDev.get() }
81-
onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() }
82-
}

buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,18 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
22
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
33
import org.jetbrains.dokka.gradle.DokkaTask
44

5+
/**
6+
* Plugin for "faker libraries"
7+
*/
8+
59
plugins {
6-
base
710
`java-library`
8-
kotlin("jvm")
911
id("org.jetbrains.dokka")
1012
id("com.github.johnrengelman.shadow")
13+
id("faker-base-conventions")
1114
id("faker-pub-conventions")
1215
}
1316

14-
configurations {
15-
create("integrationImplementation") { extendsFrom(configurations.getByName("testImplementation")) }
16-
create("integrationRuntimeOnly") {
17-
extendsFrom(
18-
configurations.getByName("testRuntimeOnly"),
19-
configurations.getByName("shadow")
20-
)
21-
}
22-
}
23-
24-
// configure sourceSets as extension since it's not available here as `sourceSets` is an extension on `Project`
25-
// https://docs.gradle.org/current/userguide/kotlin_dsl.html#project_extensions_and_conventions
26-
configure<SourceSetContainer> {
27-
create("integration") {
28-
resources.srcDir("src/integration/resources")
29-
compileClasspath += main.get().compileClasspath + test.get().compileClasspath
30-
runtimeClasspath += main.get().runtimeClasspath + test.get().runtimeClasspath
31-
}
32-
main {
33-
resources {
34-
this.srcDir("build/generated/src/main/resources")
35-
}
36-
}
37-
}
38-
3917
dependencies {
4018
val shadow by configurations
4119
val implementation by configurations
@@ -59,32 +37,6 @@ dependencies {
5937
testRuntimeOnly(libs.bundles.jackson)
6038
}
6139

62-
val integrationTest by tasks.creating(Test::class) {
63-
testClassesDirs = sourceSets["integration"].output.classesDirs
64-
classpath = sourceSets["integration"].runtimeClasspath
65-
dependsOn(tasks.test)
66-
}
67-
68-
tasks.withType<Jar> {
69-
archiveBaseName.set(fullName)
70-
71-
manifest {
72-
attributes(
73-
mapOf(
74-
"Implementation-Title" to fullName,
75-
"Implementation-Version" to project.version,
76-
/*
77-
* We can't add this here because this resolves the configuration,
78-
* after which it effectively becomes read-only and we'll get an error
79-
* Cannot change dependencies of dependency configuration ':core:implementation' after it has been included in dependency resolution
80-
* if we try to add more dependencies in the module's build.gradle file directly
81-
*/
82-
// "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name }
83-
)
84-
)
85-
}
86-
}
87-
8840
val shadowJar by tasks.getting(ShadowJar::class) {
8941
minimize()
9042
archiveBaseName.set(fullName)
@@ -116,15 +68,10 @@ val shadowJar by tasks.getting(ShadowJar::class) {
11668
from("${rootProject.rootDir.resolve("LICENSE.adoc")}") {
11769
into("META-INF")
11870
}
119-
dependsOn(integrationTest)
71+
dependsOn(tasks["integrationTest"])
12072
dependsOn(tasks.jar)
12173
}
12274

123-
artifacts {
124-
archives(sourcesJar)
125-
archives(dokkaJavadocJar)
126-
}
127-
12875
publishing {
12976
publications.withType<MavenPublication>().all {
13077
// For whatever reason I'm not able to use this in the faker-pub-conventions plugin
@@ -140,8 +87,3 @@ tasks {
14087
dependsOn(shadowJar)
14188
}
14289
}
143-
144-
tasks.withType<DokkaTask>().configureEach {
145-
onlyIf("Not dev") { !isDev.get() }
146-
onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() }
147-
}

buildSrc/src/main/kotlin/faker-provider-conventions.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.assemble
33

4+
/**
5+
* Plugin for :faker:* modules
6+
*/
7+
48
plugins {
9+
id("faker-lib-conventions")
510
}
611

712
val core = rootProject.subprojects.first { it.path == ":core" }

buildSrc/src/main/kotlin/faker-pub-conventions.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.archives
2+
3+
/**
4+
* Plugin for publishing conventions
5+
*/
6+
17
plugins {
28
`maven-publish`
39
signing
@@ -52,6 +58,13 @@ publishing {
5258
}
5359
}
5460

61+
if (!isBomModule) {
62+
artifacts {
63+
archives(sourcesJar)
64+
archives(dokkaJavadocJar)
65+
}
66+
}
67+
5568
signing {
5669
sign(publishing.publications["maven"])
5770
}

buildSrc/src/main/kotlin/yaml-to-json.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ interface Yaml2JsonPluginExtension {
66
val output: Property<File>
77
}
88

9+
/**
10+
* This plugin takes in yaml input files and outputs json files.
11+
* It's primarily used to convert the faker source dictionaries from yml to json format.
12+
*/
913
class Yaml2JsonPlugin : Plugin<Project> {
1014
val jsonMapper = ObjectMapper()
1115
// https://github.com/FasterXML/jackson-dataformats-text/issues/98

faker/books/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
plugins {
2-
`faker-lib-conventions`
32
`faker-provider-conventions`
43
}

faker/commerce/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
plugins {
2-
`faker-lib-conventions`
32
`faker-provider-conventions`
43
}

faker/creatures/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
plugins {
2-
`faker-lib-conventions`
32
`faker-provider-conventions`
43
}

faker/databases/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
plugins {
2-
`faker-lib-conventions`
32
`faker-provider-conventions`
43
}

0 commit comments

Comments
 (0)