@@ -25,7 +25,8 @@ class SemanticVersionPluginTest {
2525 companion object {
2626 @JvmStatic
2727 private fun gradleVersions (): Stream <Arguments > = Stream .of(
28- Arguments .of(" 7.4.2" )
28+ Arguments .of(" 7.4.2" ),
29+ Arguments .of(" 7.5.1" )
2930 )
3031 }
3132
@@ -366,6 +367,169 @@ class SemanticVersionPluginTest {
366367 assertTrue(valid.isEmpty())
367368 }
368369
370+ @ParameterizedTest(name = " {index} gradle version {0}" )
371+ @MethodSource(" gradleVersions" )
372+ fun `subproject version is set correctly` (gradleVersion : String ) {
373+ val build = """
374+ plugins {
375+ `java-library`
376+ `maven-publish`
377+ id("dev.poolside.gradle.semantic-version")
378+ }
379+ allprojects {
380+ apply(plugin = "java-library")
381+ apply(plugin = "maven-publish")
382+ repositories {
383+ mavenCentral()
384+ maven { url = uri("${mavenRepo.absolutePath} ") }
385+ }
386+ java {
387+ group = "dev.poolside.test"
388+ version = "0.1"
389+ }
390+ publishing {
391+ repositories {
392+ maven { url = uri("${mavenRepo.absolutePath} ") }
393+ }
394+ }
395+ }
396+ """ .trimIndent()
397+ FileManager .writeFile(folder = testProjectDir, filename = " build.gradle.kts" , content = build)
398+ val settings = """
399+ rootProject.name = "testing"
400+ include("lib")
401+ """ .trimIndent()
402+ FileManager .writeFile(folder = testProjectDir, filename = " settings.gradle.kts" , content = settings)
403+ val libBuild = """
404+ publishing {
405+ publications {
406+ create<MavenPublication>("mavenJava") {
407+ artifactId = "my-sublibrary"
408+ from(components["java"])
409+ }
410+ }
411+ }
412+ dependencies {
413+ api("org.apache.commons:commons-math3:3.6.1")
414+ implementation("com.google.guava:guava:30.1.1-jre")
415+ }
416+ """ .trimIndent()
417+ FileManager .writeFile(folder = testProjectDir, path = " lib" , filename = " build.gradle.kts" , content = libBuild)
418+ GradleRunner .create()
419+ .withPluginClasspath()
420+ .withProjectDir(testProjectDir)
421+ .withGradleVersion(gradleVersion)
422+ .withArguments(" publish" )
423+ // .withDebug(true)
424+ .build()
425+ testProjectDir.walk().filter { it.name.startsWith(" pom" ) }.forEach { pomFile ->
426+ pomFile.forEachLine { println (it) }
427+ val pom = PomParser .parse(pomFile.absolutePath)
428+ assertEquals(" 0.1.0" , pom.version)
429+ }
430+ val valid = mutableListOf (
431+ " ${mavenRepo.absolutePath} /dev/poolside/test/my-sublibrary/0.1.0/my-sublibrary-0.1.0.jar"
432+ )
433+ mavenRepo.walk().filter { it.name.endsWith(" .jar" ) }.forEach { jarFile ->
434+ if (valid.contains(jarFile.absolutePath)) {
435+ valid.remove(jarFile.absolutePath)
436+ } else {
437+ fail(" missing jarfile ${jarFile.absolutePath} " )
438+ }
439+ }
440+ assertTrue(valid.isEmpty())
441+ }
442+
443+ @ParameterizedTest(name = " {index} gradle version {0}" )
444+ @MethodSource(" gradleVersions" )
445+ fun `two subprojects version is set correctly` (gradleVersion : String ) {
446+ val build = """
447+ plugins {
448+ `java-library`
449+ `maven-publish`
450+ id("dev.poolside.gradle.semantic-version")
451+ }
452+ allprojects {
453+ apply(plugin = "java-library")
454+ apply(plugin = "maven-publish")
455+ repositories {
456+ mavenCentral()
457+ maven { url = uri("${mavenRepo.absolutePath} ") }
458+ }
459+ java {
460+ group = "dev.poolside.test"
461+ version = "0.1"
462+ }
463+ publishing {
464+ repositories {
465+ maven { url = uri("${mavenRepo.absolutePath} ") }
466+ }
467+ }
468+ }
469+ """ .trimIndent()
470+ FileManager .writeFile(folder = testProjectDir, filename = " build.gradle.kts" , content = build)
471+ val settings = """
472+ rootProject.name = "testing"
473+ include("lib")
474+ include("lib2")
475+ """ .trimIndent()
476+ FileManager .writeFile(folder = testProjectDir, filename = " settings.gradle.kts" , content = settings)
477+ val libBuild = """
478+ publishing {
479+ publications {
480+ create<MavenPublication>("mavenJava") {
481+ artifactId = "my-sublibrary"
482+ from(components["java"])
483+ }
484+ }
485+ }
486+ dependencies {
487+ api("org.apache.commons:commons-math3:3.6.1")
488+ implementation("com.google.guava:guava:30.1.1-jre")
489+ }
490+ """ .trimIndent()
491+ FileManager .writeFile(folder = testProjectDir, path = " lib" , filename = " build.gradle.kts" , content = libBuild)
492+ val lib2Build = """
493+ publishing {
494+ publications {
495+ create<MavenPublication>("mavenJava") {
496+ artifactId = "my-sublibrary2"
497+ from(components["java"])
498+ }
499+ }
500+ }
501+ dependencies {
502+ api("org.apache.commons:commons-math3:3.6.1")
503+ implementation("com.google.guava:guava:30.1.1-jre")
504+ }
505+ """ .trimIndent()
506+ FileManager .writeFile(folder = testProjectDir, path = " lib2" , filename = " build.gradle.kts" , content = lib2Build)
507+ GradleRunner .create()
508+ .withPluginClasspath()
509+ .withProjectDir(testProjectDir)
510+ .withGradleVersion(gradleVersion)
511+ .withArguments(" publish" )
512+ // .withDebug(true)
513+ .build()
514+ testProjectDir.walk().filter { it.name.startsWith(" pom" ) }.forEach { pomFile ->
515+ pomFile.forEachLine { println (it) }
516+ val pom = PomParser .parse(pomFile.absolutePath)
517+ assertEquals(" 0.1.0" , pom.version)
518+ }
519+ val valid = mutableListOf (
520+ " ${mavenRepo.absolutePath} /dev/poolside/test/my-sublibrary/0.1.0/my-sublibrary-0.1.0.jar" ,
521+ " ${mavenRepo.absolutePath} /dev/poolside/test/my-sublibrary2/0.1.0/my-sublibrary2-0.1.0.jar"
522+ )
523+ mavenRepo.walk().filter { it.name.endsWith(" .jar" ) }.forEach { jarFile ->
524+ if (valid.contains(jarFile.absolutePath)) {
525+ valid.remove(jarFile.absolutePath)
526+ } else {
527+ fail(" missing jarfile ${jarFile.absolutePath} " )
528+ }
529+ }
530+ assertTrue(valid.isEmpty())
531+ }
532+
369533 @ParameterizedTest(name = " {index} gradle version {0}" )
370534 @MethodSource(" gradleVersions" )
371535 fun `bom version set correct` (gradleVersion : String ) {
0 commit comments