Skip to content

Commit

Permalink
DEVEX-668 Fix changed task execution order in Gradle 8.12
Browse files Browse the repository at this point in the history
  • Loading branch information
windmueller committed Jan 15, 2025
1 parent f1e10cf commit 5d97763
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FirstSpirit Module Gradle Plugin
Copyright 2022 Crownpeak Technology GmbH
Copyright 2025 Crownpeak Technology GmbH

This product includes software developed at Crownpeak (https://www.crownpeak.com/).

Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [Gradle](http://www.gradle.org/) plugin to build [FirstSpirit](http://www.e-spirit.com/en/product/advantage/advantages.html) modules (FSMs)
# [Gradle](https://gradle.org/) plugin to build [FirstSpirit](https://www.crownpeak.com/de/products/content-management/) modules (FSMs)

## Usage

Expand Down Expand Up @@ -89,7 +89,7 @@ To use the plugin, include the following snippet on top of your build script:

```kotlin
plugins {
id("de.espirit.firstspirit-module") version "6.5.0"
id("de.espirit.firstspirit-module") version "6.5.1"
}
```

Expand All @@ -105,7 +105,7 @@ To use the plugin, include the following snippet on top of your build script:

```kotlin
plugins {
id("de.espirit.firstspirit-module-annotations") version "6.5.0"
id("de.espirit.firstspirit-module-annotations") version "6.5.1"
}
```

Expand All @@ -117,7 +117,7 @@ Please take a loot at (#dependency-management) for a detailed description of the

```kotlin
plugins {
id("de.espirit.firstspirit-module-configurations") version "6.5.0"
id("de.espirit.firstspirit-module-configurations") version "6.5.1"
}
```

Expand Down Expand Up @@ -168,8 +168,6 @@ Usage of classes available in the `fs-isolated-runtime.jar` that are marked as i
### checkIsolation
Like the `checkCompliance` task, this one checks for non-compliant class usages. It requires a running instance of the "FSM Dependency Detector" web application.

###

## Extension properties

The _de.espirit.firstspirit-module_ plugin defines the following extension properties in the `fsm` closure:
Expand Down Expand Up @@ -582,7 +580,7 @@ You can use the following snippet as a starting point:
// Groovy
plugins {
id 'de.espirit.firstspirit-module' version '6.5.0'
id 'de.espirit.firstspirit-module' version '6.5.1'
}
description = 'Example FSM Gradle build'
Expand Down Expand Up @@ -617,7 +615,7 @@ firstSpiritModule {
// Kotlin

plugins {
id("de.espirit.firstspirit-module") version "6.5.0"
id("de.espirit.firstspirit-module") version "6.5.1"
}

description = "Example FSM Gradle build"
Expand Down
17 changes: 9 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.github.jk1.license.filter.LicenseBundleNormalizer
import net.researchgate.release.ReleaseExtension
import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.net.URI
import java.nio.file.Files
import java.util.*
Expand All @@ -10,19 +11,19 @@ plugins {
`maven-publish`
idea
`java-gradle-plugin`
id("net.researchgate.release") version "3.0.2"
id("net.researchgate.release") version "3.1.0"
id("org.ajoberstar.grgit") version "5.0.0"
id("com.github.jk1.dependency-license-report") version "2.9"
id("org.cyclonedx.bom") version "1.7.4"
id("org.cyclonedx.bom") version "1.10.0"
}

tasks.withType<JavaCompile> {
options.release.set(11)
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "11"
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

Expand Down Expand Up @@ -116,7 +117,7 @@ sourceSets {
}
}

val writePropertiesToResourceFile = tasks.create("writePropertiesToResourceFile") {
val writePropertiesToResourceFile by tasks.registering {
outputs.upToDateWhen { false }
doLast {
val props = Properties()
Expand Down Expand Up @@ -152,7 +153,7 @@ tasks.jar {
/**
* Bundles together test classes for component scan tests
*/
val testJar = tasks.create<Jar>("testJar") {
val testJar by tasks.registering(Jar::class) {
dependsOn(tasks.testClasses)
archiveClassifier.set("tests")
from("build/classes/groovy/test")
Expand All @@ -175,7 +176,7 @@ tasks.test {
systemProperty("artifactory_password", findProperty("artifactory_password") as String)
systemProperty("gradle.version", gradle.gradleVersion)
systemProperty("version", version)
systemProperty("testJar", testJar.archiveFile.get().asFile.absolutePath)
systemProperty("testJar", testJar.get().archiveFile.get().asFile.absolutePath)
systemProperty("classesDir", layout.buildDirectory.dir("classes").get().asFile.absolutePath)

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
Expand All @@ -187,7 +188,7 @@ tasks.test {
useJUnitPlatform()
}

val integrationTest by tasks.creating(Test::class.java) {
val integrationTest by tasks.registering(Test::class) {
filter {
includeTestsMatching("*IT")
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://artifactory.e-spirit.de/artifactory/gradle-distributions/gradle-8.9-all.zip
distributionUrl=https\://artifactory.e-spirit.de/artifactory/gradle-distributions/gradle-8.12-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 1 addition & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/gradle/plugins/fsm/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fun Jar.addManifestAttribute(name: String, value: Any) {
fun Project.compileDependencies(): List<Project> {
val compileClasspath = project.configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)
val projectDependencies = compileClasspath.allDependencies.withType(ProjectDependency::class.java)
.map { it.dependencyProject }
.map { it.path }
.map { project(it) }
.filter { it.plugins.hasPlugin(JavaPlugin::class.java) }
return listOf(project) + projectDependencies
}
46 changes: 24 additions & 22 deletions src/main/kotlin/org/gradle/plugins/fsm/FSMPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,41 +60,43 @@ class FSMPlugin : Plugin<Project> {
implementation.extendsFrom(webAppsConfiguration)
}

private fun configureConfigurationTask(project: Project): Task {
val configurationTask = project.tasks.create(CONFIGURE_FSM_TASK_NAME)
configurationTask.dependsOn(project.tasks.getByName(GENERATE_LICENSE_REPORT_TASK_NAME))
configurationTask.dependsOn(JavaPlugin.JAR_TASK_NAME)

private fun configureConfigurationTask(project: Project): TaskProvider<Task> {
@Suppress("ObjectLiteralToLambda") // Lambdas cannot be used as Gradle task inputs
val action = object : Action<Task> {
override fun execute(t: Task) {
(project.tasks.getByName(FSM_TASK_NAME) as FSM).lazyConfiguration()
}
}

configurationTask.doLast(action)
val configurationTask = project.tasks.register(CONFIGURE_FSM_TASK_NAME) {
dependsOn(project.tasks.getByName(GENERATE_LICENSE_REPORT_TASK_NAME))
dependsOn(JavaPlugin.JAR_TASK_NAME)
doLast(action)
}

return configurationTask
}

private fun configureFsmTask(
project: Project,
configurationTask: Task,
configurationTask: TaskProvider<Task>,
validateTask: TaskProvider<ValidateDescriptor>
): FSM {
val fsmTask = project.tasks.create(FSM_TASK_NAME, FSM::class.java)
fsmTask.description = "Assembles an fsmTask archive containing the FirstSpirit module."
fsmTask.group = BasePlugin.BUILD_GROUP

): TaskProvider<FSM> {
removeDefaultJarArtifactFromArchives(project)

fsmTask.dependsOn(project.tasks.getByName(GENERATE_LICENSE_REPORT_TASK_NAME))
fsmTask.dependsOn(JavaPlugin.JAR_TASK_NAME)
fsmTask.dependsOn(configurationTask)
project.tasks.getByName("assemble").dependsOn(fsmTask)
val fsmTask = project.tasks.register(FSM_TASK_NAME, FSM::class.java) {
description = "Assembles an fsmTask archive containing the FirstSpirit module."
group = BasePlugin.BUILD_GROUP

// Validate FSM immediately
fsmTask.finalizedBy(validateTask)
dependsOn(project.tasks.getByName(GENERATE_LICENSE_REPORT_TASK_NAME))
dependsOn(JavaPlugin.JAR_TASK_NAME)
dependsOn(configurationTask)

// Validate FSM immediately
finalizedBy(validateTask)
}

project.tasks.getByName("assemble").dependsOn(fsmTask)

return fsmTask
}
Expand All @@ -105,20 +107,20 @@ class FSMPlugin : Plugin<Project> {
archivesConfig.artifacts.clear()
}

private fun configureValidateTask(validateTask: TaskProvider<ValidateDescriptor>, fsmTask: FSM) {
private fun configureValidateTask(validateTask: TaskProvider<ValidateDescriptor>, fsmTask: TaskProvider<FSM>) {
validateTask.configure {
description = "Validates the module descriptor."
group = LifecycleBasePlugin.VERIFICATION_GROUP
inputs.file(fsmTask.outputs.files.singleFile)
inputs.file(fsmTask.map { it.outputs.files.singleFile })
dependsOn(fsmTask)
}
}

private fun configureIsolationCheckTask(project: Project, fsmTask: FSM): TaskProvider<IsolationCheck> {
private fun configureIsolationCheckTask(project: Project, fsmTask: TaskProvider<FSM>): TaskProvider<IsolationCheck> {
val isolationCheck = project.tasks.register(ISOLATION_CHECK_TASK_NAME, IsolationCheck::class.java) {
description = "Verifies the isolation of resources in the FSM."
group = LifecycleBasePlugin.VERIFICATION_GROUP
inputs.file(fsmTask.outputs.files.singleFile)
inputs.file(fsmTask.map { it.outputs.files.singleFile })
dependsOn(fsmTask)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Resources(private val project: Project, private val webXmlPaths: List<Stri
val projectDependencies = config.allDependencies.withType(ProjectDependency::class.java)
for (projectDependency in projectDependencies) {
val scope = if (it == FS_MODULE_COMPILE_CONFIGURATION_NAME) { "module" } else { "server" }
projects.add(projectDependency.dependencyProject to scope)
projects.add(project.project(projectDependency.path) to scope)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class WebAppComponents(project: Project, private val scanResult: ComponentScan):

// fsm-resources directory of root project and fsWebCompile subprojects (shared between all webapps)
webResources.addAll(projectDependencies
.map(ProjectDependency::getDependencyProject)
.map(ProjectDependency::getPath)
.map(project::project)
.flatMap(this::fsmResources)
)

Expand All @@ -99,7 +100,7 @@ class WebAppComponents(project: Project, private val scanResult: ComponentScan):

// fsm-resources directory of current web-app
// - safety check to avoid duplicates
if (!projectDependencies.map(ProjectDependency::getDependencyProject).contains(webAppProject)) {
if (!projectDependencies.map(ProjectDependency::getPath).map(project::project).contains(webAppProject)) {
webResources.addAll(fsmResources(webAppProject))
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/org/gradle/plugins/fsm/tasks/bundling/FSM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ abstract class FSM: Jar() {
}

@TaskAction
fun generateModuleXml() {
override fun copy() {
super.copy()

logger.info("Generating module.xml files")
val archive = archiveFile.get().asFile
logger.info("Found archive ${archive.path}")
Expand Down Expand Up @@ -227,8 +229,7 @@ abstract class FSM: Jar() {

Files.createDirectories(archiveFile.get().asFile.parentFile.toPath())
Files.createFile(archiveFile.get().asFile.toPath())
super.copy()
generateModuleXml()
copy()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FSMPluginExtensionTest {

// Ensure the project has a compile dependency on the subprojects
val dependencyProjects = project.configurations.getByName(FSMPlugin.WEBAPPS_CONFIGURATION_NAME)
.dependencies.filterIsInstance<ProjectDependency>().map { it.dependencyProject }
.dependencies.filterIsInstance<ProjectDependency>().map(ProjectDependency::getPath).map(project::project)
assertThat(dependencyProjects).containsExactly(webAppSubprojectA, webAppSubprojectB)
}

Expand Down

0 comments on commit 5d97763

Please sign in to comment.