-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor buildSrc to get rid of duplicates
- Loading branch information
Showing
7 changed files
with
180 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import io.github.serpro69.semverkt.gradle.plugin.tasks.TagTask | ||
import org.gradle.accessors.dm.LibrariesForLibs | ||
import org.gradle.api.Project | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.kotlin.dsl.getByName | ||
import org.gradle.kotlin.dsl.the | ||
|
||
val Project.libs: LibrariesForLibs | ||
get() = the<LibrariesForLibs>() | ||
|
||
val Project.isBomModule: Boolean get() = path.startsWith(":bom") | ||
val Project.isCoreModule: Boolean get() = path.startsWith(":core") | ||
val Project.isFakerModule: Boolean get() = path.startsWith(":faker") | ||
val Project.isExtensionModule: Boolean get() = path.startsWith(":extension") | ||
val Project.isShadow: Boolean get() = isCoreModule || isFakerModule | ||
|
||
// versioning | ||
val Project.isDev: Provider<Boolean> | ||
get() = provider { version.toString().startsWith("0.0.0") } | ||
|
||
val Project.isSnapshot: Provider<Boolean> | ||
get() = provider { | ||
// QUESTION do we need to check if rootProject is also set to snapshot? | ||
// Likely not, since "isRelease" will not just check for the version, but also for the actual tag creation | ||
// rootProject.version.toString().endsWith("SNAPSHOT") && | ||
version.toString().endsWith("SNAPSHOT") | ||
} | ||
val Project.isRelease: Provider<Boolean> | ||
get() = provider { | ||
val tag = tasks.getByName("tag", TagTask::class) | ||
/* all fakers have their own tags, so checking if tag.didWork is enough for them, | ||
':core' shares the tag with 'root', ':bom' and ':cli-bot' modules, | ||
and hence the tag might already exist and didWork will return false for ':core' */ | ||
val tagCreated = if (project.name != "core") tag.didWork else tag.didWork || tag.tagExists | ||
!isDev.get() && !isSnapshot.get() && tagCreated | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.dokkaJavadoc | ||
import gradle.kotlin.dsl.accessors._617ff5292df7551646490c1442241820.sourceSets | ||
import org.gradle.api.Project | ||
import org.gradle.api.tasks.bundling.Jar | ||
import org.gradle.configurationcache.extensions.capitalized | ||
import org.gradle.kotlin.dsl.creating | ||
import org.gradle.kotlin.dsl.getValue | ||
|
||
/** | ||
* For additional providers, use a combination of rootProject and subproject names for artifact name and similar things. | ||
* i.e. kotlin-faker-books, kotlin-faker-movies, kotlin-faker-tv, ... | ||
* | ||
* The "core" lib retains the same name as before: kotlin-faker | ||
*/ | ||
val Project.fullName: String | ||
get() = if (name == "core") rootProject.name | ||
else "${rootProject.name}-${name}" | ||
|
||
val Project.publicationName: String | ||
get() = "Faker${path.split(":").joinToString("") { it.capitalized() }}" | ||
|
||
private fun createSourcesJarTask(p: Project): Jar { | ||
val sourcesJar by p.tasks.creating(Jar::class) { | ||
archiveClassifier.set("sources") | ||
from(p.sourceSets.getByName("main").allSource) | ||
from("${p.rootProject.rootDir.resolve("LICENSE.adoc")}") { | ||
into("META-INF") | ||
} | ||
} | ||
return sourcesJar | ||
} | ||
|
||
private fun createJavadocJarTask(p: Project): Jar { | ||
val dokkaJavadocJar by p.tasks.creating(Jar::class) { | ||
archiveClassifier.set("javadoc") | ||
dependsOn(p.tasks.dokkaJavadoc) | ||
from(p.tasks.dokkaJavadoc.get().outputDirectory.orNull) | ||
} | ||
return dokkaJavadocJar | ||
} | ||
|
||
val Project.sourcesJar: Jar | ||
get() { | ||
val sourcesJar = tasks.findByName("sourcesJar") | ||
if (sourcesJar != null && sourcesJar is Jar) { | ||
return sourcesJar | ||
} | ||
return createSourcesJarTask(this) | ||
} | ||
|
||
val Project.dokkaJavadocJar: Jar | ||
get() { | ||
val dokkaJavadocJar = tasks.findByName("dokkaJavadocJar") | ||
if (dokkaJavadocJar != null && dokkaJavadocJar is Jar) { | ||
return dokkaJavadocJar | ||
} | ||
return createJavadocJarTask(this) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.