diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 33e79b2c..61078129 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -16,41 +16,50 @@ jobs: env: WORKSPACE: ${{ github.workspace }} steps: - - uses: actions/checkout@v4 - - name: Set up JDK + - name: "📥 Checkout repository" + uses: actions/checkout@v4 + - name: "☕️ Setup JDK" uses: actions/setup-java@v4 with: - distribution: temurin + distribution: liberica java-version: ${{ matrix.java }} - - name: Run Build + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + - name: "🔨 Build project" id: build - uses: gradle/gradle-build-action@v3 env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - with: - arguments: build -Dgeb.env=chromeHeadless + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} + run: ./gradlew build publish: if: github.event_name == 'push' needs: ['build'] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up JDK + - name: "📥 Checkout repository" + uses: actions/checkout@v4 + - name: "☕️ Setup JDK" uses: actions/setup-java@v4 with: - distribution: temurin + distribution: liberica java-version: 17 - - name: Publish Artifacts (repo.grails.org) + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + - name: "📤 Publish Snapshot Artifacts to Artifactory (repo.grails.org/libs-snapshot-local)" id: publish - uses: gradle/gradle-build-action@v3 env: ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - with: - arguments: | - -Dorg.gradle.internal.publish.checksums.insecure=true - publish + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} + run: > + ./gradlew + -Dorg.gradle.internal.publish.checksums.insecure=true + publish docs: if: github.event_name == 'push' needs: publish @@ -61,18 +70,23 @@ jobs: GIT_USER_NAME: puneetbehl GIT_USER_EMAIL: behlp@unityfoundation.io steps: - - name: Checkout repository + - name: "📥 Checkout repository" uses: actions/checkout@v4 - - name: Set up JDK + - name: "☕️ Setup JDK" uses: actions/setup-java@v4 with: - distribution: temurin + distribution: liberica java-version: 17 + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - name: Generate Groovydoc id: groovydoc uses: gradle/gradle-build-action@v3 env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} with: arguments: groovydoc - name: Publish to Github Pages diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1db237d7..98f2de0f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,40 +12,43 @@ jobs: release_version: ${{ steps.release_version.outputs.value }} target_branch: ${{ steps.extract_branch.outputs.value }} env: - GIT_USER_NAME: puneetbehl - GIT_USER_EMAIL: behlp@unityfoundation.io + GIT_USER_NAME: 'grails-build' + GIT_USER_EMAIL: 'grails-build@users.noreply.github.com' steps: - - name: Checkout repository + - name: "📥 Checkout repository" uses: actions/checkout@v4 with: token: ${{ secrets.GH_TOKEN }} - - name: Set up JDK + - name: "☕️ Setup JDK" uses: actions/setup-java@v4 with: - distribution: temurin + distribution: liberica java-version: 17 - - name: Extract Target Branch + - name: "🐘 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + develocity-access-key: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + - name: "📝 Store the target branch" id: extract_branch run: | echo "Determining Target Branch" - TARGET_BRANCH=`cat $GITHUB_EVENT_PATH | jq '.release.target_commitish' | sed -e 's/^"\(.*\)"$/\1/g'` + TARGET_BRANCH=${GITHUB_REF#refs/heads/} echo $TARGET_BRANCH echo "value=${TARGET_BRANCH}" >> $GITHUB_OUTPUT - - name: Set the current release version + - name: "📝 Store the current release version" id: release_version run: echo "value=${GITHUB_REF:11}" >> $GITHUB_OUTPUT - - name: Run pre-release + - name: "⚙️ Run pre-release" uses: micronaut-projects/github-actions/pre-release@master with: token: ${{ secrets.GITHUB_TOKEN }} - - name: Run Assemble + - name: "🧩 Run Assemble" if: success() id: assemble - uses: gradle/gradle-build-action@v3 - with: - arguments: assemble env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} + run: ./gradlew assemble - name: Upload Distribution if: success() uses: actions/upload-artifact@v4 @@ -67,7 +70,8 @@ jobs: SIGNING_KEY: ${{ secrets.SIGNING_KEY }} SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} SECRING_FILE: ${{ secrets.SECRING_FILE }} - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} with: arguments: | -Psigning.secretKeyRingFile=${{ github.workspace }}/secring.gpg @@ -93,7 +97,8 @@ jobs: - name: Nexus Staging Close And Release uses: gradle/gradle-build-action@v3 env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} @@ -114,8 +119,8 @@ jobs: permissions: contents: write env: - GIT_USER_NAME: puneetbehl - GIT_USER_EMAIL: behlp@unityfoundation.io + GIT_USER_NAME: 'grails-build' + GIT_USER_EMAIL: 'grails-build@users.noreply.github.com' steps: - name: Checkout repository uses: actions/checkout@v4 @@ -131,7 +136,8 @@ jobs: id: groovydoc uses: gradle/gradle-build-action@v3 env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + DEVELOCITY_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }} + DEVELOCITY_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }} with: arguments: groovydoc - name: Publish to Github Pages diff --git a/README.md b/README.md index 4e66fcc1..38887d58 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,6 @@ grails-gsp --------- * Configure GSP Compiling Task -grails-plugin-publish ---------- -_Todo_: Add the docs - grails-plugin --------- * Configure Ast Sources @@ -41,6 +37,58 @@ grails-profile --------- _Todo_: Add the docs +grails-profile-publish +--------- +_Todo_: Add the docs + +grails-publish +--------- +A Gradle plugin to simplify publishing to either an Artifactory or Maven Central endpoint for snapshots & to Maven Central for releases. + +Example Usage: + + grailsPublish { + websiteUrl = 'http://foo.com/myplugin' + license { + name = 'Apache-2.0' + } + issueTrackerUrl = 'http://github.com/myname/myplugin/issues' + vcsUrl = 'http://github.com/myname/myplugin' + title = "My plugin title" + desc = "My plugin description" + developers = [johndoe:"John Doe"] + } + +or + + grailsPublish { + githubSlug = 'foo/bar' + license { + name = 'Apache-2.0' + } + title = "My plugin title" + desc = "My plugin description" + developers = [johndoe:"John Doe"] + } + +By default this plugin will publish to the specified Artifactory instance for snapshots, and Maven Central for releases. To change the snapshot publish behavior, you can set the `snapshotRepoType` to `RepositoryType.CENTRAL`. + +The credentials and connection url must be specified as a project property or an environment variable. + +Artifactory Environment Variables are: + + ARTIFACTORY_USERNAME + ARTIFACTORY_PASSWORD + ARTIFACTORY_URL + +Sonatype Environment Variables are: + + SONATYPE_NEXUS_URL + SONATYPE_SNAPSHOT_URL + SONATYPE_USERNAME + SONATYPE_PASSWORD + SONATYPE_STAGING_PROFILE_ID + grails-web --------- * Adds web specific extensions diff --git a/build.gradle b/build.gradle index 546d5c31..a30fa47a 100644 --- a/build.gradle +++ b/build.gradle @@ -138,15 +138,15 @@ gradlePlugin { } grailsPluginPublish { displayName = "Grails Publish Gradle Plugin" - description = 'A plugin to setup publishing to Grails central repo' - id = 'org.grails.internal.grails-plugin-publish' - implementationClass = 'org.grails.gradle.plugin.publishing.internal.GrailsCentralPublishGradlePlugin' + description = 'A plugin to assist in publishing Grails related artifacts' + id = 'org.grails.grails-plugin-publish' + implementationClass = 'org.grails.gradle.plugin.publishing.GrailsCentralPublishGradlePlugin' } grailsProfilePublish { displayName = "Grails Profile Publish Plugin" description = 'A plugin for publishing profiles' - id = 'org.grails.internal.grails-profile-publish' - implementationClass = 'org.grails.gradle.plugin.profiles.internal.GrailsProfilePublishGradlePlugin' + id = 'org.grails.grails-profile-publish' + implementationClass = 'org.grails.gradle.plugin.profiles.GrailsProfilePublishGradlePlugin' } } } diff --git a/settings.gradle b/settings.gradle index 52848cca..1dada324 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,27 +1,34 @@ plugins { -// id "com.gradle.enterprise" version "3.17.2" -// id 'com.gradle.common-custom-user-data-gradle-plugin' version '2.0.1' + id 'com.gradle.develocity' version '3.18.1' + id 'com.gradle.common-custom-user-data-gradle-plugin' version '2.0.2' } -//gradleEnterprise { -// server = 'https://ge.grails.org' -// buildScan { -// publishAlwaysIf(System.getenv('CI') == 'true') -// publishIfAuthenticated() -// uploadInBackground = System.getenv("CI") == null -// capture { -// taskInputFiles = true -// } -// } -//} +def isCI = System.getenv('CI') != null +def isLocal = !isCI +def isAuthenticated = System.getenv('DEVELOCITY_ACCESS_KEY') != null +def isBuildCacheAuthenticated = + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_USER') != null && + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') != null -//buildCache { -// local { enabled = System.getenv('CI') != 'true' } -// remote(gradleEnterprise.buildCache) { -// def isAuthenticated = System.getenv('GRADLE_ENTERPRISE_ACCESS_KEY') -// push = System.getenv('CI') == 'true' && isAuthenticated -// enabled = true -// }} +develocity { + server = 'https://ge.grails.org' + buildScan { + publishing.onlyIf { isAuthenticated } + uploadInBackground = isLocal + } +} + +buildCache { + local { enabled = isLocal } + remote(develocity.buildCache) { + push = isCI && isBuildCacheAuthenticated + enabled = true + usernameAndPassword( + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_USER') ?: '', + System.getenv('DEVELOCITY_BUILD_CACHE_NODE_KEY') ?: '' + ) + } +} rootProject.name = "grails-gradle-plugin" \ No newline at end of file diff --git a/src/main/groovy/org/grails/gradle/plugin/profiles/internal/GrailsProfilePublishGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/profiles/GrailsProfilePublishGradlePlugin.groovy similarity index 84% rename from src/main/groovy/org/grails/gradle/plugin/profiles/internal/GrailsProfilePublishGradlePlugin.groovy rename to src/main/groovy/org/grails/gradle/plugin/profiles/GrailsProfilePublishGradlePlugin.groovy index 53d544b5..04d55f15 100644 --- a/src/main/groovy/org/grails/gradle/plugin/profiles/internal/GrailsProfilePublishGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/profiles/GrailsProfilePublishGradlePlugin.groovy @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.grails.gradle.plugin.profiles.internal +package org.grails.gradle.plugin.profiles import groovy.transform.CompileStatic @@ -25,8 +25,7 @@ import org.gradle.api.artifacts.DependencySet import org.gradle.api.artifacts.SelfResolvingDependency import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.bundling.Jar -import org.grails.gradle.plugin.profiles.GrailsProfileGradlePlugin -import org.grails.gradle.plugin.publishing.internal.GrailsCentralPublishGradlePlugin +import org.grails.gradle.plugin.publishing.GrailsPublishGradlePlugin import java.nio.file.Files @@ -39,7 +38,7 @@ import static org.gradle.api.plugins.BasePlugin.BUILD_GROUP * @since 3.1 */ @CompileStatic -class GrailsProfilePublishGradlePlugin extends GrailsCentralPublishGradlePlugin { +class GrailsProfilePublishGradlePlugin extends GrailsPublishGradlePlugin { @Override void apply(Project project) { @@ -55,16 +54,6 @@ class GrailsProfilePublishGradlePlugin extends GrailsCentralPublishGradlePlugin }) } - @Override - protected String getDefaultGrailsCentralReleaseRepo() { - "https://repo.grails.org/grails/libs-releases-local" - } - - @Override - protected String getDefaultGrailsCentralSnapshotRepo() { - "https://repo.grails.org/grails/libs-snapshots-local" - } - @Override protected Map getDefaultExtraArtifact(Project project) { [source: "${project.buildDir}/classes/profile/META-INF/grails-profile/profile.yml".toString(), @@ -77,11 +66,6 @@ class GrailsProfilePublishGradlePlugin extends GrailsCentralPublishGradlePlugin 'profile' } - @Override - protected String getDefaultRepo() { - 'profiles' - } - @Override protected void doAddArtefact(Project project, MavenPublication publication) { publication.artifact(project.tasks.findByName("jar")) diff --git a/src/main/groovy/org/grails/gradle/plugin/publishing/internal/GrailsPublishExtension.groovy b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy similarity index 80% rename from src/main/groovy/org/grails/gradle/plugin/publishing/internal/GrailsPublishExtension.groovy rename to src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy index 5e3f060b..5c66b84a 100644 --- a/src/main/groovy/org/grails/gradle/plugin/publishing/internal/GrailsPublishExtension.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.grails.gradle.plugin.publishing.internal +package org.grails.gradle.plugin.publishing import groovy.transform.CompileStatic import org.gradle.util.ConfigureUtil @@ -25,29 +25,23 @@ import org.gradle.util.ConfigureUtil */ @CompileStatic class GrailsPublishExtension { - - /** - * The slug from github - */ - String githubSlug - /** - * The the publishing user + * Determines the snapshot repository to publish to */ - String user + RepositoryType snapshotRepoType = RepositoryType.ARTIFACTORY /** - * The the publishing key + * The slug from github */ - String key + String githubSlug /** - * The website URL of the plugin + * The website URL of the published project */ String websiteUrl /** - * The source control URL of the plugin + * The source control URL of the project */ String vcsUrl @@ -57,12 +51,12 @@ class GrailsPublishExtension { License license = new License() /** - * The developers of the plugin + * The developers of the project */ Map developers = [:] /** - * Title of the plugin, defaults to the project name + * Title of the project, defaults to the project name */ String title @@ -71,48 +65,11 @@ class GrailsPublishExtension { */ String desc - /** - * THe organisation on bintray - */ - String userOrg - - /** - * THe repository on bintray - */ - String repo - /** * The issue tracker URL */ String issueTrackerUrl - /** - * Whether to GPG sign - */ - boolean gpgSign = false - - /** - * The passphrase to sign, only required if `gpgSign == true` - */ - String signingPassphrase - - /** - * Whether to sync to Maven central - */ - boolean mavenCentralSync = false - - /** - * Username for maven central - */ - String sonatypeOssUsername - - /** - * Password for maven central - */ - String sonatypeOssPassword - - String snapshotUrl - License getLicense() { return license } @@ -135,6 +92,11 @@ class GrailsPublishExtension { this.license.name = license } + static enum RepositoryType { + ARTIFACTORY, // standard maven repository such as artifactory + CENTRAL // maven central + } + static class License { String name String url diff --git a/src/main/groovy/org/grails/gradle/plugin/publishing/internal/GrailsCentralPublishGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy similarity index 78% rename from src/main/groovy/org/grails/gradle/plugin/publishing/internal/GrailsCentralPublishGradlePlugin.groovy rename to src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy index 7b9c32ff..56c719a4 100644 --- a/src/main/groovy/org/grails/gradle/plugin/publishing/internal/GrailsCentralPublishGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishGradlePlugin.groovy @@ -14,7 +14,7 @@ * limitations under the License. */ //file:noinspection DuplicatedCode -package org.grails.gradle.plugin.publishing.internal +package org.grails.gradle.plugin.publishing import grails.util.GrailsNameUtils import io.github.gradlenexus.publishplugin.NexusPublishPlugin @@ -37,23 +37,17 @@ import static com.bmuschko.gradle.nexus.NexusPlugin.getSIGNING_PASSWORD import static com.bmuschko.gradle.nexus.NexusPlugin.getSIGNING_KEYRING /** - * A plugin to setup publishing to Grails central repo + * A plugin to ease publishing Grails related artifacts * * @author Graeme Rocher * @since 3.1 */ -class GrailsCentralPublishGradlePlugin implements Plugin { +class GrailsPublishGradlePlugin implements Plugin { String getErrorMessage(String missingSetting) { return """No '$missingSetting' was specified. Please provide a valid publishing configuration. Example: grailsPublish { - user = 'user' - key = 'key' - userOrg = 'my-company' // optional, otherwise published to personal bintray account - repo = 'plugins' // optional, defaults to 'plugins' - - websiteUrl = 'http://foo.com/myplugin' license { name = 'Apache-2.0' @@ -68,8 +62,6 @@ grailsPublish { or grailsPublish { - user = 'user' - key = 'key' githubSlug = 'foo/bar' license { name = 'Apache-2.0' @@ -79,15 +71,20 @@ grailsPublish { developers = [johndoe:"John Doe"] } -Your publishing user and key can also be placed in PROJECT_HOME/gradle.properties or USER_HOME/gradle.properties. For example: +The credentials and connection url must be specified as a project property or an environment variable: -bintrayUser=user -bintrayKey=key +Artifactory Environment Variables are: + ARTIFACTORY_USERNAME + ARTIFACTORY_PASSWORD + ARTIFACTORY_URL -Or using environment variables: +Sonatype Environment Variables are: + SONATYPE_NEXUS_URL + SONATYPE_SNAPSHOT_URL + SONATYPE_USERNAME + SONATYPE_PASSWORD + SONATYPE_STAGING_PROFILE_ID -BINTRAY_USER=user -BINTRAY_KEY=key """ } @@ -97,13 +94,14 @@ BINTRAY_KEY=key final TaskContainer taskContainer = project.tasks final GrailsPublishExtension gpe = extensionContainer.create("grailsPublish", GrailsPublishExtension) - final String artifactoryUsername = project.hasProperty("artifactoryPublishUsername") ? project.artifactoryPublishUsername : System.getenv("ARTIFACTORY_USERNAME") ?: '' - final String artifactoryPassword = project.hasProperty("artifactoryPublishPassword") ? project.artifactoryPublishPassword : System.getenv("ARTIFACTORY_PASSWORD") ?: '' - final String ossNexusUrl = project.hasProperty("sonatypeNexusUrl") ? project.sonatypeNexusUrl : System.getenv("SONATYPE_NEXUS_URL") ?: '' - final String ossSnapshotUrl = project.hasProperty("sonatypeSnapshotUrl") ? project.sonatypeSnapshotUrl : System.getenv("SONATYPE_SNAPSHOT_URL") ?: '' - final String ossUser = project.hasProperty("sonatypeOssUsername") ? project.sonatypeOssUsername : System.getenv("SONATYPE_USERNAME") ?: '' - final String ossPass = project.hasProperty("sonatypeOssPassword") ? project.sonatypeOssPassword : System.getenv("SONATYPE_PASSWORD") ?: '' - final String ossStagingProfileId = project.hasProperty("sonatypeOssStagingProfileId") ? project.sonatypeOssStagingProfileId : System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: '' + final String artifactoryUsername = project.findProperty("artifactoryPublishUsername") ?: System.getenv("ARTIFACTORY_USERNAME") ?: '' + final String artifactoryPassword = project.findProperty("artifactoryPublishPassword") ?: System.getenv("ARTIFACTORY_PASSWORD") ?: '' + final String artifactoryPublishUrl = project.findProperty("artifactoryPublishUrl") ?: System.getenv("ARTIFACTORY_URL") ?: '' + final String sonatypeNexusUrl = project.findProperty("sonatypeNexusUrl") ?: System.getenv("SONATYPE_NEXUS_URL") ?: '' + final String sonatypeSnapshotUrl = project.findProperty("sonatypeSnapshotUrl") ?: System.getenv("SONATYPE_SNAPSHOT_URL") ?: '' + final String sonatypeUsername = project.findProperty("sonatypeUsername") ?: System.getenv("SONATYPE_USERNAME") ?: '' + final String sonatypePassword = project.findProperty("sonatypePassword") ?: System.getenv("SONATYPE_PASSWORD") ?: '' + final String sonatypeStagingProfileId = project.findProperty("sonatypeStagingProfileId") ?: System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: '' final ExtraPropertiesExtension extraPropertiesExtension = extensionContainer.findByType(ExtraPropertiesExtension) @@ -111,27 +109,28 @@ BINTRAY_KEY=key extraPropertiesExtension.setProperty(SIGNING_PASSWORD, project.hasProperty(SIGNING_PASSWORD) ? project[SIGNING_PASSWORD] : System.getenv("SIGNING_PASSPHRASE") ?: null) extraPropertiesExtension.setProperty(SIGNING_KEYRING, project.hasProperty(SIGNING_KEYRING) ? project[SIGNING_KEYRING] : System.getenv("SIGNING_KEYRING") ?: null) - project.afterEvaluate { + GrailsPublishExtension.RepositoryType snapshotType = gpe.snapshotRepoType boolean isSnapshot = project.version.endsWith("SNAPSHOT") boolean isRelease = !isSnapshot - final PluginManager pluginManager = project.getPluginManager() - pluginManager.apply(MavenPublishPlugin.class) - - // Remove "plain" archive classifier, unless bootJar or bootWar are enabled - if (!taskContainer.findByName("bootJar")?.enabled && !taskContainer.findByName("bootWar")?.enabled) { - (taskContainer.findByName("jar") as Jar).archiveClassifier.set("") - } + final PluginManager projectPluginManager = project.getPluginManager() + final PluginManager rootProjectPluginManager = project.rootProject.getPluginManager() + projectPluginManager.apply(MavenPublishPlugin.class) project.publishing { - if (isSnapshot) { + if (isSnapshot && snapshotType == GrailsPublishExtension.RepositoryType.ARTIFACTORY) { + System.setProperty('org.gradle.internal.publish.checksums.insecure', true as String) repositories { maven { credentials { username = artifactoryUsername password = artifactoryPassword } - url gpe.snapshotUrl? gpe.snapshotUrl : getDefaultGrailsCentralSnapshotRepo() + + if(!artifactoryPublishUrl) { + throw new RuntimeException("Could not locate a project property of `artifactoryPublishUrl` or an environment variable of `ARTIFACTORY_URL` for the snapshot url") + } + url artifactoryPublishUrl } } } @@ -157,6 +156,7 @@ BINTRAY_KEY=key pom.withXml { Node pomNode = asNode() + // Prevent multiple dependencyManagement nodes if (pomNode.dependencyManagement) { pomNode.dependencyManagement[0].replaceNode {} } @@ -234,7 +234,6 @@ BINTRAY_KEY=key } if (gpe.developers) { - delegate.developers { for (entry in gpe.developers.entrySet()) { delegate.developer { @@ -264,37 +263,35 @@ BINTRAY_KEY=key } } - if (isRelease) { - pluginManager.apply(NexusPublishPlugin.class) - pluginManager.apply(SigningPlugin.class) + if (isRelease || (isSnapshot && snapshotType == GrailsPublishExtension.RepositoryType.CENTRAL)) { + rootProjectPluginManager.apply(NexusPublishPlugin.class) + projectPluginManager.apply(SigningPlugin.class) extensionContainer.configure(SigningExtension, { it.required = isRelease it.sign project.publishing.publications.maven }) - project.tasks.withType(io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository).configureEach { - shouldRunAfter(project.tasks.withType(Sign)) + project.rootProject.tasks.withType(io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository).configureEach { io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository task -> + task.setShouldRunAfter(project.tasks.withType(Sign)) } project.tasks.withType(Sign) { onlyIf { isRelease } } - } - if (isRelease) { - project.nexusPublishing { + project.rootProject.nexusPublishing { repositories { sonatype { - if (ossNexusUrl) { - nexusUrl = project.uri(ossNexusUrl) + if (sonatypeNexusUrl) { + nexusUrl = project.uri(sonatypeNexusUrl) } - if (ossSnapshotUrl) { - snapshotRepositoryUrl = project.uri(ossSnapshotUrl) + if (sonatypeSnapshotUrl) { + snapshotRepositoryUrl = project.uri(sonatypeSnapshotUrl) } - username = ossUser - password = ossPass - stagingProfileId = ossStagingProfileId + username = sonatypeUsername + password = sonatypePassword + stagingProfileId = sonatypeStagingProfileId } } } @@ -323,18 +320,6 @@ BINTRAY_KEY=key publication.from project.components.java } - protected String getDefaultArtifactType() { - "grails-$defaultClassifier" - } - - protected String getDefaultGrailsCentralReleaseRepo() { - "https://repo.grails.org/grails/plugins3-releases-local" - } - - protected String getDefaultGrailsCentralSnapshotRepo() { - "https://repo.grails.org/grails/plugins3-snapshots-local" - } - protected Map getDefaultExtraArtifact(Project project) { String pluginXml = "${project.sourceSets.main.groovy.getClassesDirectory().get().getAsFile()}/META-INF/grails-plugin.xml".toString() new File(pluginXml).exists()? [ @@ -347,13 +332,5 @@ BINTRAY_KEY=key protected String getDefaultClassifier() { "plugin" } - - protected String getDefaultDescription(Project project) { - "Grails ${project.name} $defaultClassifier" - } - - protected String getDefaultRepo() { - "plugins" - } } diff --git a/src/main/resources/META-INF/gradle-plugins/org.grails.grails-profile-publish.properties b/src/main/resources/META-INF/gradle-plugins/org.grails.grails-profile-publish.properties new file mode 100644 index 00000000..23a14a96 --- /dev/null +++ b/src/main/resources/META-INF/gradle-plugins/org.grails.grails-profile-publish.properties @@ -0,0 +1 @@ +implementation-class=org.grails.gradle.plugin.profiles.GrailsProfilePublishGradlePlugin diff --git a/src/main/resources/META-INF/gradle-plugins/org.grails.grails-publish.properties b/src/main/resources/META-INF/gradle-plugins/org.grails.grails-publish.properties new file mode 100644 index 00000000..81adad31 --- /dev/null +++ b/src/main/resources/META-INF/gradle-plugins/org.grails.grails-publish.properties @@ -0,0 +1 @@ +implementation-class=org.grails.gradle.plugin.publishing.GrailsPublishGradlePlugin diff --git a/src/main/resources/META-INF/gradle-plugins/org.grails.internal.grails-plugin-publish.properties b/src/main/resources/META-INF/gradle-plugins/org.grails.internal.grails-plugin-publish.properties deleted file mode 100644 index 4944dcca..00000000 --- a/src/main/resources/META-INF/gradle-plugins/org.grails.internal.grails-plugin-publish.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=org.grails.gradle.plugin.publishing.internal.GrailsCentralPublishGradlePlugin diff --git a/src/main/resources/META-INF/gradle-plugins/org.grails.internal.grails-profile-publish.properties b/src/main/resources/META-INF/gradle-plugins/org.grails.internal.grails-profile-publish.properties deleted file mode 100644 index 2e332bff..00000000 --- a/src/main/resources/META-INF/gradle-plugins/org.grails.internal.grails-profile-publish.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=org.grails.gradle.plugin.profiles.internal.GrailsProfilePublishGradlePlugin