diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index feb785d6..7f678452 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -32,7 +32,7 @@ jobs: DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} run: ./gradlew build publish: - if: github.event_name == 'push' + if: github.event_name == 'push' && github.repository_owner == 'grails' needs: ['build'] runs-on: ubuntu-latest steps: @@ -59,7 +59,7 @@ jobs: -Dorg.gradle.internal.publish.checksums.insecure=true publish docs: - if: github.event_name == 'push' + if: github.event_name == 'push' && github.repository_owner == 'grails' needs: publish runs-on: ubuntu-latest permissions: diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml index 047a467d..09548650 100644 --- a/.github/workflows/release-notes.yml +++ b/.github/workflows/release-notes.yml @@ -12,6 +12,7 @@ on: workflow_dispatch: jobs: release_notes: + if: github.event_name == 'push' && github.repository_owner == 'grails' permissions: contents: read runs-on: ubuntu-latest diff --git a/README.md b/README.md index 05534f39..68b39368 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ The credentials and connection url must be specified as a project property or an NEXUS_PUBLISH_SNAPSHOT_URL NEXUS_PUBLISH_STAGING_PROFILE_ID +By default, the release or snapshot state is determined by the project.version or projectVersion gradle property. To override this behavior, use the environment variable `GRAILS_PUBLISH_RELEASE` to decide if it's a release or snapshot. + grails-web --------- * Adds web specific extensions diff --git a/build.gradle b/build.gradle index 0f2cdccf..a874db2a 100644 --- a/build.gradle +++ b/build.gradle @@ -78,19 +78,30 @@ dependencies { // compile grails-gradle-plugin with the Groovy version provided by Gradle // to ensure build compatibility with Gradle, currently Groovy 3.0.x // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy - compileOnly "org.codehaus.groovy:groovy:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy:$GroovySystem.version" compileOnly "org.grails:grails-bootstrap:$grailsVersion", { exclude group: 'org.apache.groovy' + exclude group: 'org.spockframework' } compileOnly "org.grails:grails-shell:$grailsShellVersion", { exclude group: 'org.apache.groovy' + exclude group: 'org.spockframework' } - runtimeOnly "org.grails:grails-bootstrap:$grailsVersion" - runtimeOnly "org.grails:grails-shell:$grailsShellVersion" + runtimeOnly "org.grails:grails-bootstrap:$grailsVersion", { + exclude group: 'org.apache.groovy' + exclude group: 'org.spockframework' + } + runtimeOnly "org.grails:grails-shell:$grailsShellVersion", { + exclude group: 'org.apache.groovy' + exclude group: 'org.spockframework' + } + + implementation "org.grails:grails-gradle-model:$grailsVersion", { + exclude group: 'org.apache.groovy' + exclude group: 'org.spockframework' + } - implementation "org.grails:grails-gradle-model:$grailsVersion" - implementation "io.github.gradle-nexus:publish-plugin:$gradleNexusPublishPluginVersion" implementation "com.bmuschko:gradle-nexus-plugin:$gradleNexusPluginVersion" implementation "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion" @@ -238,6 +249,14 @@ publishing { } } + // publishAllPublicationsToTestCaseMavenRepoRepository + repositories { + maven { + name = "TestCaseMavenRepo" + url = layout.buildDirectory.dir('local-maven') + } + } + publications { pluginMaven(MavenPublication) { pom { @@ -280,7 +299,7 @@ publishing { } project.afterEvaluate { - project.publishing.publications.each { MavenPublication publication-> + project.publishing.publications.each { MavenPublication publication -> if (publication.name != "pluginMaven") { publication.pom.withXml { def xml = asNode() @@ -294,3 +313,4 @@ tasks.named("build").configure { finalizedBy("groovydoc") } +apply from: rootProject.layout.projectDirectory.file('gradle/e2eTest.gradle') \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index b9d34aa7..1d175e39 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,6 +5,8 @@ grailsVersion=7.0.0-SNAPSHOT grailsShellVersion=7.0.0-SNAPSHOT springBootVersion=3.4.0 springGradleDependencyManagementVersion=1.1.6 +# Since we're pulling in spring's dependency management, we need to override this to support the groovy version of gradle +spock.version=2.3-groovy-3.0 org.gradle.caching=true org.gradle.daemon=true org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1536M -XX:MaxMetaspaceSize=512M diff --git a/gradle/e2eTest.gradle b/gradle/e2eTest.gradle new file mode 100644 index 00000000..3081a903 --- /dev/null +++ b/gradle/e2eTest.gradle @@ -0,0 +1,35 @@ +def e2eTest = sourceSets.create('e2eTest') +def e2eTestTask = tasks.register('e2eTest', Test) { + group = 'verification' + testClassesDirs = sourceSets.e2eTest.output.classesDirs + classpath = sourceSets.e2eTest.runtimeClasspath + useJUnitPlatform() + systemProperty("localMavenPath", rootProject.layout.buildDirectory.dir('local-maven').get().asFile.absolutePath) + systemProperty("grailsGradlePluginVersion", rootProject.version) + + testLogging { + exceptionFormat = 'full' + events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' + } + beforeTest { descriptor -> logger.quiet " -- $descriptor" } + + dependsOn "publishAllPublicationsToTestCaseMavenRepoRepository" +} + +tasks.named("check") { + dependsOn e2eTestTask +} + +gradlePlugin { + testSourceSets e2eTest +} + +dependencies { + // Note: must use a groovy 3 compatible version of Spock + e2eTestImplementation "org.spockframework:spock-core:${project['spock.version']}", { + exclude group: 'org.apache.groovy' + } + e2eTestImplementation 'commons-io:commons-io:2.18.0' + e2eTestImplementation gradleTestKit() + e2eTestRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} \ No newline at end of file diff --git a/src/e2eTest/groovy/org/grails/gradle/test/GradleSpecification.groovy b/src/e2eTest/groovy/org/grails/gradle/test/GradleSpecification.groovy new file mode 100644 index 00000000..239a8135 --- /dev/null +++ b/src/e2eTest/groovy/org/grails/gradle/test/GradleSpecification.groovy @@ -0,0 +1,130 @@ +package org.grails.gradle.test + +import org.apache.commons.io.FileUtils +import org.gradle.testkit.runner.BuildResult +import org.gradle.testkit.runner.BuildTask +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.TaskOutcome +import spock.lang.Specification + +import java.nio.file.Files +import java.nio.file.Path + +abstract class GradleSpecification extends Specification { + private static Path basePath + + private static GradleRunner gradleRunner + + void setupSpec() { + basePath = Files.createTempDirectory("gradle-projects") + Path testKitDirectory = Files.createDirectories(basePath.resolve('.gradle')) + gradleRunner = GradleRunner.create() + .withPluginClasspath() + .withTestKitDir(testKitDirectory.toFile()) + + gradleRunner = addEnvironmentVariable( + "LOCAL_MAVEN_PATH", + System.getProperty("localMavenPath"), + gradleRunner + ) + + gradleRunner = setGradleProperty( + "grailsGradlePluginVersion", + System.getProperty("grailsGradlePluginVersion"), + gradleRunner + ) + } + + GradleRunner addEnvironmentVariable(String key, String value, GradleRunner runner) { + Map environment = runner.environment + if (environment) { + environment.put(key, value) + + return runner + } else { + return runner.withEnvironment([(key): value]) + } + } + + GradleRunner setGradleProperty(String key, String value, GradleRunner runner) { + addEnvironmentVariable("ORG_GRADLE_PROJECT_${key}", value, runner) + } + + void cleanup() { + basePath.toFile().listFiles().each { + // Reuse the gradle cache from previous tests + if (it.name == ".gradle") { + return + } + + FileUtils.deleteQuietly(it) + } + } + + void cleanupSpec() { + FileUtils.deleteQuietly(basePath.toFile()) + } + + protected GradleRunner setupTestResourceProject(String type, String projectName, String nestedProject = null) { + Objects.requireNonNull(projectName, "projectName must not be null") + + Path destinationDir = basePath.resolve(type) + Files.createDirectories(destinationDir) + + Path sourceProjectDir = Path.of("src/e2eTest/resources/publish-projects/$type/$projectName") + FileUtils.copyDirectoryToDirectory(sourceProjectDir.toFile(), destinationDir.toFile()) + + setupProject(destinationDir.resolve(projectName).resolve(nestedProject ?: '.')) + } + + protected GradleRunner setupProject(Path projectDirectory) { + gradleRunner.withProjectDir(projectDirectory.toFile()) + } + + protected Path createProjectDir(String projectName) { + Objects.requireNonNull(projectName, "projectName must not be null") + + Path destinationDir = basePath.resolve(projectName) + Files.createDirectories(destinationDir) + + destinationDir + } + + protected BuildResult executeTask(String taskName, List otherArguments = [], GradleRunner gradleRunner) { + List arguments = [taskName, "--stacktrace"] + arguments.addAll(otherArguments) + + gradleRunner.withArguments(arguments).forwardOutput().build() + } + + protected void assertTaskSuccess(String taskName, BuildResult result) { + def tasks = result.tasks.find { it.path.endsWith(":${taskName}") } + if (!tasks) { + throw new IllegalStateException("No tasks were found for `${taskName}`") + } + + tasks.each { BuildTask task -> + if (task.outcome != TaskOutcome.SUCCESS) { + throw new IllegalStateException("Task $taskName failed with outcome $task.outcome") + } + } + } + + protected void assertBuildSuccess(BuildResult result, List ignoreTaskNames = []) { + def results = result.tasks.groupBy { it.outcome } + + for (String ignoredTaskName : ignoreTaskNames) { + for (BuildTask ignoredTask : result.tasks.findAll { it.path.endsWith("${ignoredTaskName}") }) { + def taskOutComeTasks = results.get(ignoredTask.outcome) + taskOutComeTasks.remove(ignoredTask) + if (!taskOutComeTasks) { + results.remove(ignoredTask.outcome) + } + } + } + + if (results.keySet().size() != 1) { + throw new IllegalStateException("Unexpected Task failures: ${results.findAll { it.key != TaskOutcome.SUCCESS }}") + } + } +} diff --git a/src/e2eTest/groovy/org/grails/gradle/test/GrailsPublishPluginSpec.groovy b/src/e2eTest/groovy/org/grails/gradle/test/GrailsPublishPluginSpec.groovy new file mode 100644 index 00000000..9b3d50b9 --- /dev/null +++ b/src/e2eTest/groovy/org/grails/gradle/test/GrailsPublishPluginSpec.groovy @@ -0,0 +1,579 @@ +package org.grails.gradle.test + +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.UnexpectedBuildFailure +import spock.lang.PendingFeature + +import java.nio.file.Path + +class GrailsPublishPluginSpec extends GradleSpecification { + def "gradle config works when not publishing - snapshot - maven publish - legacy-apply - multi-project-no-subproject-build-gradle-publish-all"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-no-subproject-build-gradle-publish-all') + + when: + def result = executeTask("assemble", ["--info"], runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + !result.output.contains("Environment Variable `GRAILS_PUBLISH_RELEASE` detected - using variable instead of project version.") + result.output.contains("Project subproject1 will be a snapshot.") + !result.output.contains("Project subproject1 will be a release.") + result.output.contains("Project subproject2 will be a snapshot.") + !result.output.contains("Project subproject2 will be a release.") + } + + def "gradle config works when not publishing - snapshot - maven publish - legacy-apply - multi-project-no-subproject-build-gradle-publish-per-project"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-no-subproject-build-gradle-publish-per-project') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - snapshot - maven publish - legacy-apply - multi-project-parent-child-setup-per-project-parent-published"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-parent-child-setup-per-project-parent-published') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - snapshot - maven publish - legacy-apply - child-project-with-unrelated-parent - eval parent"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'child-project-with-unrelated-parent') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - snapshot - maven publish - legacy-apply - child-project-with-unrelated-parent - eval child"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'child-project-with-unrelated-parent', 'otherProject') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - snapshot - maven publish - legacy-apply - multi-project-parent-child-setup-per-project-child-published"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-parent-child-setup-per-project-child-published') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - snapshot - maven publish - legacy-apply - multi-project-with-subproject-gradle"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-with-subproject-gradle') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - snapshot - maven publish - plugins-block - multi-project-parent-child-setup-per-project-parent-published"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'multi-project-parent-child-setup-per-project-parent-published') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("Project subproject2 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-SNAPSHOT.") + result.output.contains("Project subproject1 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-SNAPSHOT.") + } + + def "gradle config works when not publishing - snapshot - maven publish - plugins-block - child-project-with-unrelated-parent - eval parent"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'child-project-with-unrelated-parent') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("Project subproject2 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-SNAPSHOT.") + result.output.contains("Project subproject1 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-SNAPSHOT.") + } + + def "gradle config works when not publishing - snapshot - maven publish - plugins-block - child-project-with-unrelated-parent - eval child"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'child-project-with-unrelated-parent', 'otherProject') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("Project subproject2 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-SNAPSHOT.") + result.output.contains("Project subproject1 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-SNAPSHOT.") + } + + def "gradle config works when not publishing - snapshot - maven publish - plugins-block - multi-project-parent-child-setup-per-project-child-published"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'multi-project-parent-child-setup-per-project-child-published') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - snapshot - maven publish - plugins-block - multi-project-with-subproject-gradle"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'multi-project-with-subproject-gradle') + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - milestone - maven publish - legacy-apply - multi-project-no-subproject-build-gradle-publish-all"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-no-subproject-build-gradle-publish-all') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - milestone - maven publish - legacy-apply - multi-project-no-subproject-build-gradle-publish-per-project"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-no-subproject-build-gradle-publish-per-project') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - milestone - maven publish - legacy-apply - multi-project-parent-child-setup-per-project-parent-published"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-parent-child-setup-per-project-parent-published') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - milestone - maven publish - legacy-apply - child-project-with-unrelated-parent - eval parent"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'child-project-with-unrelated-parent') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - milestone - maven publish - legacy-apply - child-project-with-unrelated-parent - eval child"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'child-project-with-unrelated-parent', 'otherProject') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + @PendingFeature(reason = "Failed to apply plugin class 'io.github.gradlenexus.publishplugin.NexusPublishPlugin'") + def "gradle config works when not publishing - milestone - maven publish - legacy-apply - multi-project-parent-child-setup-per-project-child-published"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-parent-child-setup-per-project-child-published') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + @PendingFeature(reason = "Failed to apply plugin class 'io.github.gradlenexus.publishplugin.NexusPublishPlugin'") + def "gradle config works when not publishing - milestone - maven publish - legacy-apply - multi-project-with-subproject-gradle"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-with-subproject-gradle') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "gradle config works when not publishing - milestone - maven publish - plugins-block - multi-project-parent-child-setup-per-project-parent-published"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'multi-project-parent-child-setup-per-project-parent-published') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + result.output.contains("Project subproject1 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-M1.") + } + + def "gradle config works when not publishing - milestone - maven publish - plugins-block - child-project-with-unrelated-parent - eval parent"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'child-project-with-unrelated-parent') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + result.output.contains("Project subproject1 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-M1.") + } + + def "gradle config works when not publishing - milestone - maven publish - plugins-block - child-project-with-unrelated-parent - eval child"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'child-project-with-unrelated-parent', 'otherProject') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + result.output.contains("Project subproject1 does not have a version defined. Using the gradle property `projectVersion` to assume version is 0.0.1-M1.") + } + + @PendingFeature(reason = "Failed to apply plugin class 'io.github.gradlenexus.publishplugin.NexusPublishPlugin'") + def "gradle config works when not publishing - milestone - maven publish - plugins-block - multi-project-parent-child-setup-per-project-child-published"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'multi-project-parent-child-setup-per-project-child-published') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + @PendingFeature(reason = "Failed to apply plugin class 'io.github.gradlenexus.publishplugin.NexusPublishPlugin'") + def "gradle config works when not publishing - milestone - maven publish - plugins-block - multi-project-with-subproject-gradle"() { + given: + GradleRunner runner = setupTestResourceProject('plugins-block', 'multi-project-with-subproject-gradle') + + setGradleProperty( + "projectVersion", + "0.0.1-M1", + runner + ) + + when: + def result = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + } + + def "project fails on maven publish without url"() { + given: + Path projectDir = createProjectDir("invalid-sources") + + GradleRunner runner = setupProject(projectDir) + + projectDir.resolve("settings.gradle").toFile().text = """ + rootProject.name = 'invalid-sources' + """ + + Path sourceDirectory = projectDir.resolve("src").resolve("main").resolve("groovy") + sourceDirectory.toFile().mkdirs() + + sourceDirectory.resolve("Example.groovy").toFile().text = """ + class Example { + String name + } + """ + + projectDir.resolve('build.gradle').toFile().text = """ + buildscript { + repositories { + maven { url "\${System.getenv('LOCAL_MAVEN_PATH')}\" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:\$grailsGradlePluginVersion" + } + } + + version "0.0.1-SNAPSHOT" + group "org.grails.example" + + apply plugin: 'java-library' + apply plugin: 'groovy' + + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } + + dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' + } + + apply plugin: 'org.grails.grails-publish' + grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] + } + """ + + when: + def assembleResult = executeTask("assemble", runner) + + then: + assertTaskSuccess("assemble", assembleResult) + assertBuildSuccess(assembleResult, ["compileJava", "processResources"]) + + when: + runner = addEnvironmentVariable("MAVEN_PUBLISH_USERNAME", "publishUser", runner) + runner = addEnvironmentVariable("MAVEN_PUBLISH_PASSWORD", "publishPassword", runner) + + executeTask("publish", runner) + + then: + UnexpectedBuildFailure bf = thrown(UnexpectedBuildFailure) + bf.buildResult.output.contains("Could not locate a project property of `mavenPublishUrl` or an environment variable of `MAVEN_PUBLISH_URL`. A URL is required for maven publishing.") + } + + def "project without sources fails grailsPublish apply"() { + given: + Path projectDir = createProjectDir("invalid-sources") + + GradleRunner runner = setupProject(projectDir) + + projectDir.resolve("settings.gradle").toFile().text = """ + rootProject.name = 'invalid-sources' + """ + + projectDir.resolve('build.gradle').toFile().text = """ + buildscript { + repositories { + maven { url "\${System.getenv('LOCAL_MAVEN_PATH')}\" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:\$grailsGradlePluginVersion" + } + } + + version "0.0.1" + + apply plugin: 'org.grails.grails-publish' + """ + + when: + executeTask("assemble", runner) + + then: + UnexpectedBuildFailure bf = thrown(UnexpectedBuildFailure) + bf.buildResult.output.contains("Cannot apply Grails Publish Plugin. Project invalid-sources does not have any components to publish.") + } + + def "project with environment variable based snapshot or release detection - is snapshot"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-no-subproject-build-gradle-publish-all') + + runner = setGradleProperty("projectVersion", "0.0.1-M1", runner) + runner = addEnvironmentVariable("GRAILS_PUBLISH_RELEASE", "false", runner) + + when: + def result = executeTask("assemble", ["--info"], runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + result.output.contains("Environment Variable `GRAILS_PUBLISH_RELEASE` detected - using variable instead of project version.") + result.output.contains("Project subproject1 will be a snapshot.") + result.output.contains("Project subproject2 will be a snapshot.") + } + + def "project with environment variable based snapshot or release detection - is release"() { + given: + GradleRunner runner = setupTestResourceProject('legacy-apply', 'multi-project-no-subproject-build-gradle-publish-all') + + runner = setGradleProperty("projectVersion", "0.0.1-SNAPSHOT", runner) + runner = addEnvironmentVariable("GRAILS_PUBLISH_RELEASE", "true", runner) + + when: + def result = executeTask("assemble", ["--info"], runner) + + then: + assertTaskSuccess("assemble", result) + assertBuildSuccess(result, ["compileJava", "processResources"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + result.output.contains("Environment Variable `GRAILS_PUBLISH_RELEASE` detected - using variable instead of project version.") + result.output.contains("Project subproject1 will be a release.") + result.output.contains("Project subproject2 will be a release.") + } +} diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/build.gradle new file mode 100644 index 00000000..32bc3f53 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/build.gradle @@ -0,0 +1,36 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +repositories { + maven { url = 'https://repo.grails.org/grails/core' } +} + +version "${projectVersion}" +group "org.grails.example" + +apply plugin: 'java-library' +apply plugin: 'groovy' + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +apply plugin: 'org.grails.grails-publish' +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/gradle.properties b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/build.gradle new file mode 100644 index 00000000..4206a367 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/build.gradle @@ -0,0 +1,14 @@ +repositories { + maven { url = 'https://repo.grails.org/grails/core' } +} + +version "${projectVersion}" +group "org.grails.example" + +apply plugin: 'java-library' +apply plugin: 'groovy' + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' + implementation 'org.grails.example:subproject1' +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/gradle.properties b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/settings.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/settings.gradle new file mode 100644 index 00000000..41051305 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'otherProject' + +includeBuild("../") \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/otherProject/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/settings.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/settings.gradle new file mode 100644 index 00000000..3f172a06 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'subproject1' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/child-project-with-unrelated-parent/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/build.gradle new file mode 100644 index 00000000..64862b53 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/build.gradle @@ -0,0 +1,42 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +version "${projectVersion}" +group "org.grails.example" + +subprojects { project -> + version "${projectVersion}" + group "org.grails.example" + + apply plugin: 'java-library' + apply plugin: 'groovy' + + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } + + dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' + } + + apply plugin: 'org.grails.grails-publish' + grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] + } +} + diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/gradle.properties b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/settings.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/settings.gradle new file mode 100644 index 00000000..bab4066a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/settings.gradle @@ -0,0 +1,5 @@ +rootProject.name = 'multi-project-no-subproject-build-gradle-root' + +include 'subproject1' +include 'subproject2' + diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/subproject2/src/main/groovy/org/grails/example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/subproject2/src/main/groovy/org/grails/example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-all/subproject2/src/main/groovy/org/grails/example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/build.gradle new file mode 100644 index 00000000..f2591427 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/build.gradle @@ -0,0 +1,46 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +version "${projectVersion}" +group "org.grails.example" + +subprojects { project -> + version "${projectVersion}" + group "org.grails.example" + + apply plugin: 'java-library' + apply plugin: 'groovy' + + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } + + dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' + } + + if(project.name == "subproject1") { + apply plugin: 'org.grails.grails-publish' + grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] + } + } + else { + logger.lifecycle("Not applying grails-publish plugin to project `${project.name}`") + } +} diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/gradle.properties b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/settings.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/settings.gradle new file mode 100644 index 00000000..b63f52a9 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/settings.gradle @@ -0,0 +1,4 @@ +rootProject.name = 'multi-project-no-subproject-build-gradle-root' + +include 'subproject1' +include 'subproject2' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-no-subproject-build-gradle-publish-per-project/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/build.gradle new file mode 100644 index 00000000..6eb2a839 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/build.gradle @@ -0,0 +1,33 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +allprojects { + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } +} + +version "${projectVersion}" +group "org.grails.example" + +apply plugin: 'java-library' +apply plugin: 'groovy' + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +subprojects { project -> + version "${projectVersion}" + group "org.grails.example" + + apply plugin: 'java-library' + apply plugin: 'groovy' +} diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/gradle.properties b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/settings.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/settings.gradle new file mode 100644 index 00000000..1dba1309 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'subproject1' + +include 'subproject2' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/subproject2/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/subproject2/build.gradle new file mode 100644 index 00000000..2c83d130 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/subproject2/build.gradle @@ -0,0 +1,16 @@ +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +apply plugin: 'org.grails.grails-publish' +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-child-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/build.gradle new file mode 100644 index 00000000..8e1e318e --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/build.gradle @@ -0,0 +1,40 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +allprojects { + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } + + version "${projectVersion}" + group "org.grails.example" + + apply plugin: 'java-library' + apply plugin: 'groovy' + + dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' + } +} + + + +apply plugin: 'org.grails.grails-publish' +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/gradle.properties b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/settings.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/settings.gradle new file mode 100644 index 00000000..1dba1309 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'subproject1' + +include 'subproject2' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/subproject2/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/subproject2/build.gradle new file mode 100644 index 00000000..f8fec106 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/subproject2/build.gradle @@ -0,0 +1,3 @@ +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-parent-child-setup-per-project-parent-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/build.gradle new file mode 100644 index 00000000..5e88b447 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/build.gradle @@ -0,0 +1,26 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +allprojects { + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } +} + +version "${projectVersion}" +group "org.grails.example" + +subprojects { project -> + apply plugin: 'java-library' + apply plugin: 'groovy' + + version "${projectVersion}" + group "org.grails.example" +} diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/gradle.properties b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/settings.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/settings.gradle new file mode 100644 index 00000000..b63f52a9 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/settings.gradle @@ -0,0 +1,4 @@ +rootProject.name = 'multi-project-no-subproject-build-gradle-root' + +include 'subproject1' +include 'subproject2' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject1/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject1/build.gradle new file mode 100644 index 00000000..999c2ec5 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject1/build.gradle @@ -0,0 +1,5 @@ +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +logger.lifecycle("Not applying grails-publish plugin to project `${project.name}`") \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject2/build.gradle b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject2/build.gradle new file mode 100644 index 00000000..2c83d130 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject2/build.gradle @@ -0,0 +1,16 @@ +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +apply plugin: 'org.grails.grails-publish' +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/legacy-apply/multi-project-with-subproject-gradle/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/build.gradle new file mode 100644 index 00000000..c4992c10 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/build.gradle @@ -0,0 +1,38 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +plugins { + id 'java-library' + id 'groovy' + id 'org.grails.grails-publish' +} + +repositories { + maven { url = 'https://repo.grails.org/grails/core' } +} + +version "${projectVersion}" +group "org.grails.example" + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/gradle.properties b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/build.gradle new file mode 100644 index 00000000..ddf7e0cd --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/build.gradle @@ -0,0 +1,26 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +plugins { + id 'java-library' + id 'groovy' +} + +repositories { + maven { url = 'https://repo.grails.org/grails/core' } +} + +version "${projectVersion}" +group "org.grails.example" + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' + implementation 'org.grails.example:subproject1' +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/gradle.properties b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/settings.gradle b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/settings.gradle new file mode 100644 index 00000000..41051305 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'otherProject' + +includeBuild("../") \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/otherProject/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/settings.gradle b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/settings.gradle new file mode 100644 index 00000000..3f172a06 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'subproject1' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/child-project-with-unrelated-parent/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/build.gradle new file mode 100644 index 00000000..f915a48a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/build.gradle @@ -0,0 +1,32 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +plugins { + id 'java-library' + id 'groovy' +} + +allprojects { + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } +} + +version "${projectVersion}" +group "org.grails.example" + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +subprojects { project -> + version "${projectVersion}" + group "org.grails.example" +} diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/gradle.properties b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/settings.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/settings.gradle new file mode 100644 index 00000000..1dba1309 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'subproject1' + +include 'subproject2' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/subproject2/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/subproject2/build.gradle new file mode 100644 index 00000000..2d5d780e --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/subproject2/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java-library' + id 'groovy' + id 'org.grails.grails-publish' +} + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-child-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/build.gradle new file mode 100644 index 00000000..49cfb861 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/build.gradle @@ -0,0 +1,43 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +plugins { + id 'java-library' + id 'groovy' + id 'org.grails.grails-publish' +} + +version "${projectVersion}" +group "org.grails.example" + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +allprojects { + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } + + version "${projectVersion}" + group "org.grails.example" +} + +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/gradle.properties b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/settings.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/settings.gradle new file mode 100644 index 00000000..1dba1309 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'subproject1' + +include 'subproject2' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/subproject2/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/subproject2/build.gradle new file mode 100644 index 00000000..1ed36ebf --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/subproject2/build.gradle @@ -0,0 +1,8 @@ +plugins { + id 'java-library' + id 'groovy' +} + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-parent-child-setup-per-project-parent-published/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/build.gradle new file mode 100644 index 00000000..1dc73396 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/build.gradle @@ -0,0 +1,23 @@ +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/core' } + } + dependencies { + classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion" + } +} + +allprojects { + repositories { + maven { url = 'https://repo.grails.org/grails/core' } + } +} + +version "${projectVersion}" +group "org.grails.example" + +subprojects { project -> + version "${projectVersion}" + group "org.grails.example" +} diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/gradle.properties b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/gradle.properties new file mode 100644 index 00000000..e0f33cc2 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/gradle.properties @@ -0,0 +1 @@ +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/settings.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/settings.gradle new file mode 100644 index 00000000..b63f52a9 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/settings.gradle @@ -0,0 +1,4 @@ +rootProject.name = 'multi-project-no-subproject-build-gradle-root' + +include 'subproject1' +include 'subproject2' \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject1/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject1/build.gradle new file mode 100644 index 00000000..4b863ed6 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject1/build.gradle @@ -0,0 +1,10 @@ +plugins { + id 'java-library' + id 'groovy' +} + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +logger.lifecycle("Not applying grails-publish plugin to project `${project.name}`") \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy new file mode 100644 index 00000000..54df8e20 --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject1/src/main/groovy/org/grails/example/SubProject1.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject1 { + def sayHello() { + println "Hello from SubProject1" + } +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject2/build.gradle b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject2/build.gradle new file mode 100644 index 00000000..2d5d780e --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject2/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java-library' + id 'groovy' + id 'org.grails.grails-publish' +} + +dependencies { + implementation 'org.apache.groovy:groovy-all:4.0.24' +} + +grailsPublish { + githubSlug = 'grails/grails-gradle-plugin' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] +} \ No newline at end of file diff --git a/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy new file mode 100644 index 00000000..56750d0a --- /dev/null +++ b/src/e2eTest/resources/publish-projects/plugins-block/multi-project-with-subproject-gradle/subproject2/src/main/groovy/org.grails.example/SubProject2.groovy @@ -0,0 +1,7 @@ +package org.grails.example + +class SubProject2 { + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy index dc224a69..fccf10b6 100644 --- a/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy @@ -27,6 +27,7 @@ import org.gradle.api.plugins.PluginManager import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.plugins.MavenPublishPlugin import org.gradle.api.tasks.TaskContainer +import org.gradle.api.tasks.TaskProvider import org.gradle.plugins.signing.Sign import org.gradle.plugins.signing.SigningExtension import org.gradle.plugins.signing.SigningPlugin @@ -45,6 +46,9 @@ import static com.bmuschko.gradle.nexus.NexusPlugin.getSIGNING_KEYRING class GrailsPublishGradlePlugin implements Plugin { public static String NEXUS_PUBLISH_PLUGIN_ID = 'io.github.gradle-nexus.publish-plugin' + public static String MAVEN_PUBLISH_PLUGIN_ID = 'maven-publish' + public static String SIGNING_PLUGIN_ID = 'signing' + public static String ENVIRONMENT_VARIABLE_BASED_RELEASE = 'GRAILS_PUBLISH_RELEASE' String getErrorMessage(String missingSetting) { return """No '$missingSetting' was specified. Please provide a valid publishing configuration. Example: @@ -123,19 +127,32 @@ Note: if project properties are used, the properties must be defined prior to ap PublishType snapshotPublishType = gpe.snapshotPublishType PublishType releasePublishType = gpe.releasePublishType - String detectedVersion = (project.version == Project.DEFAULT_VERSION ? (project.findProperty('projectVersion') ?: Project.DEFAULT_VERSION) : project.version) as String - if (detectedVersion == Project.DEFAULT_VERSION) { - throw new IllegalStateException("Project `${project.name}` has an unspecified version (neither `version` or the property `projectVersion` is defined). Release state cannot be determined.") + boolean isSnapshot, isRelease + if (System.getenv(ENVIRONMENT_VARIABLE_BASED_RELEASE) != null) { + // Detect release state based on environment variables instead of versions + isRelease = Boolean.parseBoolean(System.getenv(ENVIRONMENT_VARIABLE_BASED_RELEASE)) + isSnapshot = !isRelease + + project.rootProject.logger.lifecycle("Environment Variable `$ENVIRONMENT_VARIABLE_BASED_RELEASE` detected - using variable instead of project version.") + } else { + String detectedVersion = (project.version == Project.DEFAULT_VERSION ? (project.findProperty('projectVersion') ?: Project.DEFAULT_VERSION) : project.version) as String + if (detectedVersion == Project.DEFAULT_VERSION) { + throw new IllegalStateException("Project ${project.name} has an unspecified version (neither `version` or the property `projectVersion` is defined). Release state cannot be determined.") + } + if (project.version == Project.DEFAULT_VERSION) { + project.rootProject.logger.warn("Project ${project.name} does not have a version defined. Using the gradle property `projectVersion` to assume version is ${detectedVersion}.") + } + project.rootProject.logger.info("Version $detectedVersion detected for project ${project.name}") + + isSnapshot = detectedVersion.endsWith('SNAPSHOT') + isRelease = !isSnapshot } - project.rootProject.logger.info("Version $detectedVersion detected for project ${project.name}") - boolean isSnapshot = detectedVersion.endsWith('SNAPSHOT') if (isSnapshot) { - project.rootProject.logger.info("Snapshot version detected for project ${project.name}") + project.rootProject.logger.info("Project ${project.name} will be a snapshot.") } - boolean isRelease = !isSnapshot if (isRelease) { - project.rootProject.logger.info("Release detected for Project `${project.name}`") + project.rootProject.logger.info("Project ${project.name} will be a release.") } boolean useMavenPublish = (isSnapshot && snapshotPublishType == PublishType.MAVEN_PUBLISH) || (isRelease && releasePublishType == PublishType.MAVEN_PUBLISH) @@ -151,26 +168,33 @@ Note: if project properties are used, the properties must be defined prior to ap final PluginManager projectPluginManager = project.pluginManager projectPluginManager.apply(MavenPublishPlugin) + if (isRelease || useNexusPublish) { + if (project.pluginManager.hasPlugin(SIGNING_PLUGIN_ID)) { + project.logger.debug("Signing Plugin already applied to project ${project.name}") + } else { + projectPluginManager.apply(SigningPlugin) + } + + project.tasks.withType(Sign).configureEach { Sign task -> + task.onlyIf { isRelease } + } + } + if (useNexusPublish) { // The nexus plugin is special since it must always be applied to the root project. // Handle when multiple subprojects exist and grailsPublish is defined in each one instead of at the root. final PluginManager rootProjectPluginManager = project.rootProject.pluginManager boolean hasNexusPublishApplied = rootProjectPluginManager.hasPlugin(NEXUS_PUBLISH_PLUGIN_ID) if (hasNexusPublishApplied) { - project.rootProject.logger.info("Nexus Publish Plugin already applied to root project") - } - else { + project.rootProject.logger.debug("Nexus Publish Plugin already applied to root project") + } else { rootProjectPluginManager.apply(NexusPublishPlugin) } - projectPluginManager.apply(SigningPlugin) - - project.rootProject.tasks.withType(InitializeNexusStagingRepository).configureEach { InitializeNexusStagingRepository task -> - task.shouldRunAfter = project.tasks.withType(Sign) - } - - project.tasks.withType(Sign) { - onlyIf { isRelease } + if (isRelease) { + project.rootProject.tasks.withType(InitializeNexusStagingRepository).configureEach { InitializeNexusStagingRepository task -> + task.shouldRunAfter = project.tasks.withType(Sign) + } } if (!hasNexusPublishApplied) { @@ -193,8 +217,10 @@ Note: if project properties are used, the properties must be defined prior to ap } project.afterEvaluate { + validateProjectState(project) project.publishing { if (useMavenPublish) { + addMavenPublishValidations(project, mavenPublishUrl) System.setProperty('org.gradle.internal.publish.checksums.insecure', true as String) repositories { maven { @@ -202,12 +228,6 @@ Note: if project properties are used, the properties must be defined prior to ap username = mavenPublishUsername password = mavenPublishPassword } - - if (!mavenPublishUrl) { - // TODO: Need to only apply this when trying to publish - // throw new RuntimeException('Could not locate a project property of `mavenPublishUrl` or an environment variable of `MAVEN_PUBLISH_URL`. A URL is required for maven publishing.') - } - url = mavenPublishUrl } } @@ -337,7 +357,7 @@ Note: if project properties are used, the properties must be defined prior to ap } } - if (useNexusPublish) { + if (isRelease) { extensionContainer.configure(SigningExtension, { it.required = isRelease it.sign project.publishing.publications.maven @@ -363,6 +383,22 @@ Note: if project properties are used, the properties must be defined prior to ap } } + private void addMavenPublishValidations(Project project, def mavenPublishUrl) { + project.plugins.withId(MAVEN_PUBLISH_PLUGIN_ID) { + TaskProvider publishTask = project.tasks.named("publish") + + TaskProvider validateBeforePublish = project.tasks.register("requireMavenPublishUrl") { + if (!mavenPublishUrl) { + throw new RuntimeException('Could not locate a project property of `mavenPublishUrl` or an environment variable of `MAVEN_PUBLISH_URL`. A URL is required for maven publishing.') + } + } + + publishTask.configure { + it.dependsOn validateBeforePublish + } + } + } + protected void doAddArtefact(Project project, MavenPublication publication) { publication.from project.components.java } @@ -379,5 +415,11 @@ Note: if project properties are used, the properties must be defined prior to ap protected String getDefaultClassifier() { 'plugin' } + + private validateProjectState(Project project) { + if (!project.components) { + throw new RuntimeException("Cannot apply Grails Publish Plugin. Project ${project.name} does not have any components to publish.") + } + } }