Skip to content

Commit

Permalink
Merge pull request #10 from iodigital-com/ci-fix
Browse files Browse the repository at this point in the history
Only task to leave projects
  • Loading branch information
crysxd authored Nov 4, 2024
2 parents 7367641 + 93138a3 commit e6ebd39
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,35 @@ class GradleBomPluginFunctionalTest {
""".trimIndent()
)

writeString(
File(projectDir, "child/build.gradle"),
"""
dependencies {
}
""".trimIndent()
)

writeString(
File(projectDir, "child/child/build.gradle"),
"""
dependencies {
}
""".trimIndent()
)

writeString(
File(projectDir, "settings.gradle"),
"""
include(":child")
include(":child:child")
""".trimIndent()
)

// Run the build
val result = GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withArguments("generateBom", "--configuration=test")
.withArguments(":generateBom", "--configuration=test")
.withProjectDir(projectDir)
.withEnvironment(mapOf("mockDependencyTreeFile" to mockFile.absolutePath))
.build()
Expand Down Expand Up @@ -65,6 +89,7 @@ class GradleBomPluginFunctionalTest {

@Throws(IOException::class)
private fun writeString(file: File, string: String) {
file.parentFile.mkdirs()
FileWriter(file).use { writer ->
writer.write(string)
}
Expand Down
26 changes: 14 additions & 12 deletions gradle-bom/src/main/java/com/iodigital/gradlebom/GradleBomPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ class GradleBomPlugin : Plugin<Project> {
private fun Project.createTasks(): Unit = afterEvaluate {
val suffix = "Implementation"

project.tasks.register(
"generateBom",
GenericGenerateModuleBomTask::class.java
)
// Skip if already added
if (!project.tasks.names.contains("generateBom")) {
project.tasks.register(
"generateBom",
GenericGenerateModuleBomTask::class.java
)

configurations
.filter { it.name.endsWith(suffix) }
.map { it.name.removeSuffix(suffix) }
.distinct()
.sorted()
.forEach { config ->
if (project.subprojects.isEmpty()) {
configurations
.filter { it.name.endsWith(suffix) }
.map { it.name.removeSuffix(suffix) }
.distinct()
.sorted()
.forEach { config ->
project.tasks.register(
"generate${config.replaceFirstChar { it.uppercase() }}Bom",
SpecificGenerateModuleBomTask::class.java,
config
)
}
}
}

// Iterate over subprojects
subprojects.forEach { sub ->
sub.createTasks()
}
Expand Down

0 comments on commit e6ebd39

Please sign in to comment.