Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.grails.grails-web & org.grails.grails-gsp Gradle Plugin ids with versions not working for snapshots #351

Open
jamesfredley opened this issue Nov 10, 2024 · 9 comments

Comments

@jamesfredley
Copy link
Contributor

jamesfredley commented Nov 10, 2024

org.grails.grails-web & org.grails.grails-gsp Gradle Plugin ids work with 6.2.1, but not with 6.2.2-SNAPSHOT. We must be missing something when we publish the grails-gradle-plugin snapshots to repo.grails.org.

The workaround is to use:

apply plugin: 'org.grails.grails-web'
apply plugin: 'org.grails.grails-gsp'

which does allow the project to load and gradle downloads the following files. Only the jar file has a definition for these ids.

Download https://repo.grails.org/grails/core/org/grails/grails-gradle-plugin/6.2.2-SNAPSHOT/maven-metadata.xml, took 1 s 522 ms
Download https://repo.grails.org/grails/core/org/grails/grails-gradle-plugin/6.2.2-SNAPSHOT/grails-gradle-plugin-6.2.2-20241107.044227-3.pom, took 46 ms
Download https://repo.grails.org/grails/core/org/grails/grails-gradle-plugin/6.2.2-SNAPSHOT/grails-gradle-plugin-6.2.2-20241107.044227-3.module, took 51 ms
Download https://repo.grails.org/grails/core/org/grails/grails-gradle-plugin/6.2.2-SNAPSHOT/grails-gradle-plugin-6.2.2-20241107.044227-3.jar, took 301 ms

6.2.1 works fine

buildscript {
    repositories {
        maven { url "https://repo.grails.org/grails/core" }
        mavenCentral()
    }
    dependencies { // Not Published to Gradle Plugin Portal
        classpath "org.grails:grails-gradle-plugin:6.2.1"
    }
}
plugins {
    id "groovy"
    id "org.grails.grails-web" version "6.2.1"
    id "org.grails.grails-gsp" version "6.2.1"
    id "com.github.erdi.webdriver-binaries" version "3.2"
    id "war"
    id "idea"
    id "com.bertramlabs.asset-pipeline" version "4.3.0"
    id "application"
    id "eclipse"
}

6.2.2-SNAPSHOT fails

buildscript {
    repositories {
        maven { url "https://repo.grails.org/grails/core" }
        mavenCentral()
    }
    dependencies { // Not Published to Gradle Plugin Portal
        classpath "org.grails:grails-gradle-plugin:6.2.2-SNAPSHOT"
    }
}
plugins {
    id "groovy"
    id "org.grails.grails-web" version "6.2.2-SNAPSHOT"
    id "org.grails.grails-gsp" version "6.2.2-SNAPSHOT"
    id "com.github.erdi.webdriver-binaries" version "3.2"
    id "war"
    id "idea"
    id "com.bertramlabs.asset-pipeline" version "4.3.0"
    id "application"
    id "eclipse"
}
Plugin [id: 'org.grails.grails-web', version: '6.2.2-SNAPSHOT'] was not found in any of the following sources:

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'org.grails.grails-web', version: '6.2.2-SNAPSHOT'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.grails.grails-web:org.grails.grails-web.gradle.plugin:6.2.2-SNAPSHOT')
  Searched in the following repositories:
    Gradle Central Plugin Repository

These plugins are not published to the Gradle Central Plugin Repository

https://plugins.gradle.org/search?term=org.grails.grails-web
https://plugins.gradle.org/search?term=org.grails.grails-gsp
https://plugins.gradle.org/search?term=grails-gradle-plugin

@jamesfredley
Copy link
Contributor Author

These gradle plugins will load by version number if placed in settings.gradle, which downloads the pom file from the directories above, and can then be references by id in build.gradle, since they have already been loaded by settings.gradle. The version number cannot be repeated in build.gradle.

settings.gradle

pluginManagement {
    repositories {
        maven { url "https://repo.grails.org/grails/core/" }
    }
    plugins {
        id "org.grails.grails-web" version "6.2.2-SNAPSHOT"
        id "org.grails.grails-gsp" version "6.2.2-SNAPSHOT"
    }
}

build.gradle

plugins {
        id "groovy"
        id "org.grails.grails-gsp"
        id "org.grails.grails-web"
        id "war"
        id "idea"
        id "com.bertramlabs.asset-pipeline" version "5.0.1"
        id "application"
        id "eclipse"
}

@codeconsole
Copy link
Contributor

codeconsole commented Nov 10, 2024

This works as designed. It uses the version of grails-gradle-plugin that is in the class path because they are resolved from within that jar. You would never have a different version of the plugins.

This will be fixed when we break up and publish the plugins independently.

See #340

@jamesfredley
Copy link
Contributor Author

But why does a release version work with id and version and a snapshot fails with id or id and version? See full example in first comment.

works with classpath "org.grails:grails-gradle-plugin:6.2.1"

    id "org.grails.grails-web" version "6.2.1"
    id "org.grails.grails-gsp" version "6.2.1"

fails with classpath "org.grails:grails-gradle-plugin:6.2.2-SNAPSHOT"

    id "org.grails.grails-web" version "6.2.2-SNAPSHOT"
    id "org.grails.grails-gsp" version "6.2.2-SNAPSHOT"

fails with classpath "org.grails:grails-gradle-plugin:6.2.2-SNAPSHOT"

    id "org.grails.grails-web"
    id "org.grails.grails-gsp"

@codeconsole
Copy link
Contributor

perhaps because gradle plugins don't support snapshots?

why are you setting the version in settings.gradle?

@jamesfredley
Copy link
Contributor Author

The main example at the top does not use settings.gradle or buildSrc. There is an example lower down with settings.gradle, to show the different behavior.

@jamesfredley
Copy link
Contributor Author

@codeconsole @jdaugherty

TLDR; Gradle is not finding the snapshot Gradle plugins due to the long file name and it doesn't appear to process maven-metadata.xml to find the filename for Gradle plugins referenced by id/version or id.

Release Gradle Plugins:
https://mvnrepository.com/artifact/org.grails.grails-web/org.grails.grails-web.gradle.plugin
https://repo.grails.org/ui/native/core/org/grails/grails-web/org.grails.grails-web.gradle.plugin/6.2.1/

https://mvnrepository.com/artifact/org.grails.grails-gsp/org.grails.grails-gsp.gradle.plugin
https://repo.grails.org/ui/native/core/org/grails/grails-gsp/org.grails.grails-gsp.gradle.plugin/6.2.1/

Snapshot Gradle Plugins:
The snapshots also live in https://repo.grails.org/ui/native/core/org/grails/grails-gsp/org.grails.grails-gsp.gradle.plugin/ but instead of org.grails.grails-gsp.gradle.plugin-7.0.0-SNAPSHOT.pom the filename is org.grails.grails-gsp.gradle.plugin-7.0.0-20241208.224809-42.pom and I don't think Gradle is reading maven-metadata.xml to determine the filename since maven-metadata.xml does not exist for a release https://repo.grails.org/ui/native/core/org/grails/grails-gsp/org.grails.grails-gsp.gradle.plugin/6.2.1/

@jamesfredley
Copy link
Contributor Author

When using apply plugin: or settings.gradle, Gradle does check maven-metadata.xml to find the filename.

You can see that in #351 (comment) and #351 (comment) is the same.

We should stick with apply plugin: for Grails Gradle Plugins like org.grails.grails-web or org.grails.grails-gsp since it works for release and snapshot versions.

This might also be worth submitting an issue and PR over on Gradle to make plugins{} in build.gradle work the same as pluginManagement { plugins{}} in settings.gradle.

@jdaugherty
Copy link
Contributor

FYI: the plugins work if the buildSrc imports the bom. That's the biggest reason to use the build source. But when they're in the plugins{} block, they are evaluated differently than when they're applied.

The real reason for this is because the grails gradle plugin is often written to lookup tasks that exist at the time they are applied, and not after evaluation. This has the side effect that depending on the plugin load order (or apply order), you'll get unexpected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants