Skip to content

Commit

Permalink
Add support for JPMS via Multi-Release Jar (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Mar 18, 2024
1 parent 5741ed4 commit a214b8d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 49 deletions.
7 changes: 5 additions & 2 deletions build-logic/src/main/kotlin/-KmpConfigurationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
import io.matthewnelson.kmp.configuration.ExperimentalKmpConfigurationApi
import io.matthewnelson.kmp.configuration.extension.KmpConfigurationExtension
import io.matthewnelson.kmp.configuration.extension.container.target.KmpConfigurationContainerDsl
import org.gradle.api.Action
import org.gradle.api.JavaVersion

fun KmpConfigurationExtension.configureShared(
java9ModuleName: String? = null,
publish: Boolean = false,
explicitApi: Boolean = true,
action: Action<KmpConfigurationContainerDsl>
) {
configure {
jvm {
target { withJava() }

kotlinJvmTarget = JavaVersion.VERSION_1_8
compileSourceCompatibility = JavaVersion.VERSION_1_8
compileTargetCompatibility = JavaVersion.VERSION_1_8

@OptIn(ExperimentalKmpConfigurationApi::class)
java9MultiReleaseModuleInfo(java9ModuleName)
}

js()
Expand Down
38 changes: 1 addition & 37 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension

plugins {
alias(libs.plugins.multiplatform) apply(false)
alias(libs.plugins.binaryCompat)
alias(libs.plugins.gradleVersions)
}

allprojects {
Expand All @@ -40,41 +38,7 @@ plugins.withType<YarnPlugin> {
}

apiValidation {
@Suppress("LocalVariableName")
val CHECK_PUBLICATION = findProperty("CHECK_PUBLICATION") as? String

if (CHECK_PUBLICATION != null) {
if (findProperty("CHECK_PUBLICATION") != null) {
ignoredProjects.add("check-publication")
}
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}

tasks.withType<DependencyUpdatesTask> {
// Example 1: reject all non stable versions
rejectVersionIf {
isNonStable(candidate.version)
}

// Example 2: disallow release candidates as upgradable versions from stable versions
rejectVersionIf {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}

// Example 3: using the full syntax
resolutionStrategy {
componentSelection {
@Suppress("RedundantSamConstructor")
all(Action {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject("Release candidate")
}
})
}
}
}
12 changes: 5 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[versions]
binaryCompat = "0.13.2"
configuration = "0.1.5"
encoding = "2.1.0"
binaryCompat = "0.14.0"
configuration = "0.2.1"
encoding = "2.2.1"
endians = "0.2.0"
gradleVersions = "0.50.0"
kotlin = "1.9.21"
publish = "0.25.3"
kotlin = "1.9.23"
publish = "0.27.0"

[libraries]
gradle-kmp-configuration = { module = "io.matthewnelson:gradle-kmp-configuration-plugin", version.ref = "configuration" }
Expand All @@ -19,4 +18,3 @@ endians-endians = { module = "org.kotlincrypto.endians:endians", version.ref = "
[plugins]
binaryCompat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompat" }
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" }
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

# https://gradle.org/release-checksums/
distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionSha256Sum=85719317abd2112f021d4f41f09ec370534ba288432065f4b477b6a3b652910d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
2 changes: 1 addition & 1 deletion library/keccak/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plugins {
}

kmpConfiguration {
configureShared(publish = true) {
configureShared(java9ModuleName = "org.kotlincrypto.sponges.keccak", publish = true) {
common {
sourceSetTest {
dependencies {
Expand Down
5 changes: 5 additions & 0 deletions library/keccak/src/jvmMain/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module org.kotlincrypto.sponges.keccak {
requires kotlin.stdlib;

exports org.kotlincrypto.sponges.keccak;
}

0 comments on commit a214b8d

Please sign in to comment.