Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conflicts between gradle plugins and imports in multiplatform projects #3095

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions alchemist-graphql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import Libs.alchemist
import Libs.incarnation
import com.apollographql.apollo3.gradle.internal.ApolloGenerateSourcesTask
import com.expediagroup.graphql.plugin.gradle.tasks.AbstractGenerateClientTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.gitlab.arturbosch.detekt.Detekt
import java.io.File.separator

plugins {
application
alias(libs.plugins.kotest.multiplatform)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ktor)
alias(libs.plugins.graphql.server)
alias(libs.plugins.graphql.client)
}
Expand Down Expand Up @@ -70,10 +67,6 @@ kotlin {
}
}

application {
mainClass.set("it.unibo.alchemist.Alchemist")
}

graphql {
schema {
packages = listOf(
Expand Down Expand Up @@ -127,30 +120,18 @@ tasks.withType<ApolloGenerateSourcesTask>().configureEach {
*/
val webpackTask = tasks.named("jsBrowserProductionWebpack")

tasks.named("run", JavaExec::class).configure {
classpath(
tasks.named("compileKotlinJvm"),
configurations.named("jvmRuntimeClasspath"),
webpackTask.map { task ->
task.outputs.files.map { file ->
file.parent
}
},
)
}

/**
* Configure the [ShadowJar] task to work exactly like the "jvmJar" task of Kotlin Multiplatform, but also
* Configure the shadowJar task to work exactly like the "jvmJar" task of Kotlin Multiplatform, but also
* include the JS artifacts by depending on the "jsBrowserProductionWebpack" task.
*/
tasks.withType<ShadowJar>().configureEach {
val jvmJarTask = tasks.named("jvmJar")
from(webpackTask)
from(jvmJarTask)
from(tasks.named("jsBrowserDistribution"))
mustRunAfter(tasks.distTar, tasks.distZip)
archiveClassifier.set("all")
}
// tasks.withType<ShadowJar>().configureEach {
// val jvmJarTask = tasks.named("jvmJar")
// from(webpackTask)
// from(jvmJarTask)
// from(tasks.named("jsBrowserDistribution"))
// mustRunAfter(tasks.distTar, tasks.distZip)
// archiveClassifier.set("all")
// }

fun PatternFilterable.excludeGenerated() = exclude { "build${separator}generated" in it.file.absolutePath }
tasks.withType<Detekt>().configureEach { excludeGenerated() }
Expand Down
17 changes: 0 additions & 17 deletions alchemist-web-renderer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Libs.alchemist
import Libs.incarnation

plugins {
application
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotest.multiplatform)
}
Expand Down Expand Up @@ -86,27 +85,11 @@ kotlin {
}
}

application {
mainClass.set("it.unibo.alchemist.Alchemist")
}

/**
* Webpack task that generates the JS artifacts.
*/
val webpackTask = tasks.named("jsBrowserProductionWebpack")

tasks.named("run", JavaExec::class).configure {
classpath(
tasks.named("compileKotlinJvm"),
configurations.named("jvmRuntimeClasspath"),
webpackTask.map { task ->
task.outputs.files.map { file ->
file.parent
}
},
)
}

/*
* Configure the shadowJar task to work exactly like the "jvmJar" task of Kotlin Multiplatform, but also
* include the JS artifacts by depending on the "jsBrowserProductionWebpack" task.
Expand Down
132 changes: 65 additions & 67 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,22 @@ plugins {
val minJavaVersion: String by properties

allprojects {

with(rootProject.libs.plugins) {
if (project.isMultiplatform) {
apply(plugin = kotlin.multiplatform.id)
} else {
apply(plugin = kotlin.jvm.id)
apply(plugin = multiJvmTesting.id)
apply(plugin = java.qa.id)
}
apply(plugin = dokka.id)
apply(plugin = gitSemVer.id)
apply(plugin = java.qa.id)
apply(plugin = multiJvmTesting.id)
apply(plugin = kotlin.qa.id)
apply(plugin = publishOnCentral.id)
apply(plugin = taskTree.id)
}
apply(plugin = "distribution")

multiJvm {
jvmVersionForCompilation.set(minJavaVersion.toInt())
maximumSupportedJvmVersion.set(latestJava)
if (isInCI && (isWindows || isMac)) {
/*
* Reduce time in CI by running on fewer JVMs on slower or more limited instances.
*/
testByDefaultWith(latestJava)
}
}

repositories {
google()
mavenCentral()
Expand All @@ -83,8 +71,70 @@ allprojects {
}

// JVM PROJECTS CONFIGURATIONS

if (!project.isMultiplatform) {
// CODE QUALITY

javaQA {
checkstyle {
additionalConfiguration.set(
"""
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="Math\s*\.\s*random\s*\(\s*\)" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Don't use Math.random() inside Alchemist. Breaks stuff." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="class\s*\.\s*forName\s*\(" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Use the library to load classes and resources. Breaks grid otherwise." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="class\s*\.\s*getResource" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Use the library to load classes and resources. Breaks grid otherwise." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="class\s*\.\s*getClassLoader" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Use the library to load classes and resources. Breaks grid otherwise." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="warning" />
<property name="format" value="@author" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Do not use @author. Changes and authors are tracked by the content manager." />
</module>
""".trimIndent(),
)
additionalSuppressions.set(
"""
<suppress files=".*[\\/]expressions[\\/]parser[\\/].*" checks=".*"/>
<suppress files=".*[\\/]biochemistrydsl[\\/].*" checks=".*"/>
""".trimIndent(),
)
}
}

multiJvm {
jvmVersionForCompilation.set(minJavaVersion.toInt())
maximumSupportedJvmVersion.set(latestJava)
if (isInCI && (isWindows || isMac)) {
/*
* Reduce time in CI by running on fewer JVMs on slower or more limited instances.
*/
testByDefaultWith(latestJava)
}
}

dependencies {
with(rootProject.libs) {
compileOnly(spotbugs.annotations)
Expand Down Expand Up @@ -202,58 +252,6 @@ allprojects {
maxHeapSize = "1g"
}

// CODE QUALITY

javaQA {
checkstyle {
additionalConfiguration.set(
"""
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="Math\s*\.\s*random\s*\(\s*\)" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Don't use Math.random() inside Alchemist. Breaks stuff." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="class\s*\.\s*forName\s*\(" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Use the library to load classes and resources. Breaks grid otherwise." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="class\s*\.\s*getResource" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Use the library to load classes and resources. Breaks grid otherwise." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="error" />
<property name="format" value="class\s*\.\s*getClassLoader" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Use the library to load classes and resources. Breaks grid otherwise." />
</module>
<module name="RegexpSingleline">
<property name="severity" value="warning" />
<property name="format" value="@author" />
<property name="fileExtensions" value="java,xtend,scala,kt" />
<property name="message"
value="Do not use @author. Changes and authors are tracked by the content manager." />
</module>
""".trimIndent(),
)
additionalSuppressions.set(
"""
<suppress files=".*[\\/]expressions[\\/]parser[\\/].*" checks=".*"/>
<suppress files=".*[\\/]biochemistrydsl[\\/].*" checks=".*"/>
""".trimIndent(),
)
}
}

tasks.withType<com.github.spotbugs.snom.SpotBugsTask>().configureEach {
reports {
create("html") { enabled = true }
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-qa = "org.danilopianini.gradle-kotlin-qa:0.59.1"
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
multiJvmTesting = "org.danilopianini.multi-jvm-test-plugin:0.5.5"
publishOnCentral = "org.danilopianini.publish-on-central:5.0.23"
scalafmt = "cz.alenkacz.gradle.scalafmt:1.16.2"
Expand Down
Loading