-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break up build script into convention plugins
The library will be split up into modules, so this makes parts of the build configuration easy to reuse.
- Loading branch information
1 parent
8c3c570
commit a0a7a0a
Showing
8 changed files
with
276 additions
and
151 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
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,24 @@ | ||
/* | ||
* Copyright 2024 Ben Woodworth | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192 | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
buildSrc/src/main/kotlin/binary-compatibility-validator-conventions.gradle.kts
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,28 @@ | ||
/* | ||
* Copyright 2024 Ben Woodworth | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import kotlinx.validation.ExperimentalBCVApi | ||
|
||
plugins { | ||
id("org.jetbrains.kotlinx.binary-compatibility-validator") | ||
} | ||
|
||
apiValidation { | ||
@OptIn(ExperimentalBCVApi::class) | ||
klib { | ||
enabled = true | ||
} | ||
} |
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,76 @@ | ||
/* | ||
* Copyright 2024 Ben Woodworth | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
} | ||
|
||
val ciHostTargets = run { | ||
val hostTargetPrefixes = mapOf( | ||
"linux" to listOf("metadata", "jvm", "js", "linux", "android", "wasm"), | ||
"macos" to listOf("macos", "ios", "watchos", "tvos"), | ||
"windows" to listOf("mingw") | ||
) | ||
|
||
val hostTargets = hostTargetPrefixes.mapValues { (_, prefixes) -> | ||
kotlin.targets.filter { target -> | ||
prefixes.any { target.name.startsWith(it) } | ||
} | ||
} | ||
|
||
val envCiHost = System.getenv("CI_HOST") | ||
val osName = System.getProperty("os.name") | ||
val host = when { | ||
envCiHost != null -> envCiHost.also { | ||
require(envCiHost in hostTargets) { "Invalid CI_HOST: $envCiHost. Must be one of: ${hostTargets.keys}" } | ||
} | ||
|
||
osName == "Linux" -> "linux" | ||
osName == "Mac OS X" -> "macos" | ||
osName.startsWith("Windows") -> "windows" | ||
else -> error("Unable to determine CI Host for OS: $osName. CI_HOST env can be set instead.") | ||
} | ||
|
||
// Check for non-existent, unaccounted for, or double-counted targets | ||
val allTargets = kotlin.targets.map { it.name }.sorted() | ||
val groupedTargets = hostTargets.values.flatten().map { it.name }.sorted() | ||
check(groupedTargets == allTargets) { | ||
"Bad host target grouping.\n\tExpected: $allTargets\n\tActual: $groupedTargets" | ||
} | ||
|
||
hostTargets[host]!!.asSequence() | ||
} | ||
|
||
tasks.create("ciTest") { | ||
ciHostTargets | ||
.filterIsInstance<KotlinTargetWithTests<*, *>>() | ||
.map { target -> "${target.name}Test" } | ||
.forEach { targetTest -> | ||
dependsOn(targetTest) | ||
} | ||
} | ||
|
||
tasks.create("ciPublish") { | ||
ciHostTargets | ||
.map { it.name.replaceFirstChar(Char::uppercase) } | ||
.map { if (it == "Metadata") "KotlinMultiplatform" else it } | ||
.map { target -> "publish${target}PublicationToMavenRepository" } | ||
.forEach { publishTarget -> | ||
dependsOn(publishTarget) | ||
} | ||
} |
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,41 @@ | ||
/* | ||
* Copyright 2024 Ben Woodworth | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import org.jetbrains.dokka.gradle.DokkaTask | ||
import java.net.URL | ||
|
||
plugins { | ||
id("org.jetbrains.dokka") | ||
} | ||
|
||
tasks.withType<DokkaTask>().configureEach { | ||
dokkaSourceSets.configureEach { | ||
reportUndocumented = true | ||
failOnWarning = true | ||
|
||
val releaseVersionRef = version.toString() | ||
.takeIf { version -> version.matches(Regex("""\d+\.\d+\.\d+""")) } | ||
?.let { version -> "v$version" } | ||
|
||
if (releaseVersionRef != null) { | ||
sourceLink { | ||
localDirectory = rootDir | ||
remoteUrl = URL("https://github.com/BenWoodworth/Parameterize/tree/$releaseVersionRef") | ||
remoteLineSuffix = "#L" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.