Skip to content

Commit

Permalink
Extract more stuff to a 'base' plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed May 29, 2024
1 parent b1a8136 commit ba5fe1b
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 153 deletions.
98 changes: 98 additions & 0 deletions buildSrc/src/main/kotlin/faker-base-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.assemble
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.jar
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.sourceSets
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.test
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.DokkaTask

/**
* Plugin for base build setup of faker modules with kotlin
*/

plugins {
base
kotlin("jvm")
id("org.jetbrains.dokka")
}

configurations {
create("integrationImplementation") { extendsFrom(configurations.getByName("testImplementation")) }
create("integrationRuntimeOnly") {
if (isShadow) {
extendsFrom(
configurations.getByName("testRuntimeOnly"),
configurations.getByName("shadow"),
)
} else {
extendsFrom(configurations.getByName("testRuntimeOnly"))
}
}
}

// configure sourceSets as extension since it's not available here as `sourceSets` is an extension on `Project`
// https://docs.gradle.org/current/userguide/kotlin_dsl.html#project_extensions_and_conventions
configure<SourceSetContainer> {
create("integration") {
resources.srcDir("src/integration/resources")
compileClasspath += main.get().compileClasspath + test.get().compileClasspath
runtimeClasspath += main.get().runtimeClasspath + test.get().runtimeClasspath
}
main {
resources {
this.srcDir("build/generated/src/main/resources")
}
}
}

val integrationTest by tasks.creating(Test::class) {
testClassesDirs = sourceSets["integration"].output.classesDirs
classpath = sourceSets["integration"].runtimeClasspath
dependsOn(tasks.test)
}

tasks.withType<Jar> {
archiveBaseName.set(fullName)

manifest {
attributes(
mapOf(
"Implementation-Title" to fullName,
"Implementation-Version" to project.version,
/*
* We can't add this here because this resolves the configuration,
* after which it effectively becomes read-only and we'll get an error
* Cannot change dependencies of dependency configuration ':core:implementation' after it has been included in dependency resolution
* if we try to add more dependencies in the module's build.gradle file directly
*/
// "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name }
)
)
}
}

tasks {
assemble {
dependsOn(jar)
}
}

tasks {
jar {
dependsOn(integrationTest)
}
assemble {
dependsOn(integrationTest)
}
}

tasks.withType<DokkaTask>().configureEach {
onlyIf("Not dev") { !isDev.get() }
onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() }
}
77 changes: 4 additions & 73 deletions buildSrc/src/main/kotlin/faker-ext-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,82 +1,13 @@
import org.jetbrains.dokka.gradle.DokkaTask
/**
* Plugin for :extension:* modules
*/

plugins {
base
kotlin("jvm")
id("org.jetbrains.dokka")
id("faker-base-conventions")
id("faker-pub-conventions")
}

configurations {
create("integrationImplementation") { extendsFrom(configurations.getByName("testImplementation")) }
create("integrationRuntimeOnly") {
extendsFrom(
configurations.getByName("testRuntimeOnly"),
)
}
}

// configure sourceSets as extension since it's not available here as `sourceSets` is an extension on `Project`
// https://docs.gradle.org/current/userguide/kotlin_dsl.html#project_extensions_and_conventions
configure<SourceSetContainer> {
create("integration") {
resources.srcDir("src/integration/resources")
compileClasspath += main.get().compileClasspath + test.get().compileClasspath
runtimeClasspath += main.get().runtimeClasspath + test.get().runtimeClasspath
}
main {
resources {
this.srcDir("build/generated/src/main/resources")
}
}
}

dependencies {
val implementation by configurations
implementation(libs.bundles.kotlin)
}

val integrationTest by tasks.creating(Test::class) {
testClassesDirs = sourceSets["integration"].output.classesDirs
classpath = sourceSets["integration"].runtimeClasspath
dependsOn(tasks.test)
}

tasks.withType<Jar> {
archiveBaseName.set(fullName)

manifest {
attributes(
mapOf(
"Implementation-Title" to fullName,
"Implementation-Version" to project.version,
/*
* We can't add this here because this resolves the configuration,
* after which it effectively becomes read-only and we'll get an error
* Cannot change dependencies of dependency configuration ':core:implementation' after it has been included in dependency resolution
* if we try to add more dependencies in the module's build.gradle file directly
*/
// "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name }
)
)
}

dependsOn(integrationTest)
}

artifacts {
archives(sourcesJar)
archives(dokkaJavadocJar)
}

tasks {
assemble {
dependsOn(integrationTest)
dependsOn(jar)
}
}

tasks.withType<DokkaTask>().configureEach {
onlyIf("Not dev") { !isDev.get() }
onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() }
}
70 changes: 6 additions & 64 deletions buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,18 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.dokka.gradle.DokkaTask

/**
* Plugin for "faker libraries"
*/

plugins {
base
`java-library`
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.github.johnrengelman.shadow")
id("faker-base-conventions")
id("faker-pub-conventions")
}

configurations {
create("integrationImplementation") { extendsFrom(configurations.getByName("testImplementation")) }
create("integrationRuntimeOnly") {
extendsFrom(
configurations.getByName("testRuntimeOnly"),
configurations.getByName("shadow")
)
}
}

// configure sourceSets as extension since it's not available here as `sourceSets` is an extension on `Project`
// https://docs.gradle.org/current/userguide/kotlin_dsl.html#project_extensions_and_conventions
configure<SourceSetContainer> {
create("integration") {
resources.srcDir("src/integration/resources")
compileClasspath += main.get().compileClasspath + test.get().compileClasspath
runtimeClasspath += main.get().runtimeClasspath + test.get().runtimeClasspath
}
main {
resources {
this.srcDir("build/generated/src/main/resources")
}
}
}

dependencies {
val shadow by configurations
val implementation by configurations
Expand All @@ -59,32 +37,6 @@ dependencies {
testRuntimeOnly(libs.bundles.jackson)
}

val integrationTest by tasks.creating(Test::class) {
testClassesDirs = sourceSets["integration"].output.classesDirs
classpath = sourceSets["integration"].runtimeClasspath
dependsOn(tasks.test)
}

tasks.withType<Jar> {
archiveBaseName.set(fullName)

manifest {
attributes(
mapOf(
"Implementation-Title" to fullName,
"Implementation-Version" to project.version,
/*
* We can't add this here because this resolves the configuration,
* after which it effectively becomes read-only and we'll get an error
* Cannot change dependencies of dependency configuration ':core:implementation' after it has been included in dependency resolution
* if we try to add more dependencies in the module's build.gradle file directly
*/
// "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name }
)
)
}
}

val shadowJar by tasks.getting(ShadowJar::class) {
minimize()
archiveBaseName.set(fullName)
Expand Down Expand Up @@ -116,15 +68,10 @@ val shadowJar by tasks.getting(ShadowJar::class) {
from("${rootProject.rootDir.resolve("LICENSE.adoc")}") {
into("META-INF")
}
dependsOn(integrationTest)
dependsOn(tasks["integrationTest"])
dependsOn(tasks.jar)
}

artifacts {
archives(sourcesJar)
archives(dokkaJavadocJar)
}

publishing {
publications.withType<MavenPublication>().all {
// For whatever reason I'm not able to use this in the faker-pub-conventions plugin
Expand All @@ -140,8 +87,3 @@ tasks {
dependsOn(shadowJar)
}
}

tasks.withType<DokkaTask>().configureEach {
onlyIf("Not dev") { !isDev.get() }
onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.assemble

/**
* Plugin for :faker:* modules
*/

plugins {
id("faker-lib-conventions")
}

val core = rootProject.subprojects.first { it.path == ":core" }
Expand Down
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/faker-pub-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.archives

/**
* Plugin for publishing conventions
*/

plugins {
`maven-publish`
signing
Expand Down Expand Up @@ -52,6 +58,13 @@ publishing {
}
}

if (!isBomModule) {
artifacts {
archives(sourcesJar)
archives(dokkaJavadocJar)
}
}

signing {
sign(publishing.publications["maven"])
}
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/yaml-to-json.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface Yaml2JsonPluginExtension {
val output: Property<File>
}

/**
* This plugin takes in yaml input files and outputs json files.
* It's primarily used to convert the faker source dictionaries from yml to json format.
*/
class Yaml2JsonPlugin : Plugin<Project> {
val jsonMapper = ObjectMapper()
// https://github.com/FasterXML/jackson-dataformats-text/issues/98
Expand Down
1 change: 0 additions & 1 deletion faker/books/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/commerce/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/creatures/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/databases/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/edu/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/games/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/humor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/japmedia/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/lorem/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/misc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/movies/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
1 change: 0 additions & 1 deletion faker/music/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
plugins {
`faker-lib-conventions`
`faker-provider-conventions`
}
Loading

0 comments on commit ba5fe1b

Please sign in to comment.