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

Please also check buildSrc #284

Open
Vampire opened this issue Jan 7, 2019 · 6 comments
Open

Please also check buildSrc #284

Vampire opened this issue Jan 7, 2019 · 6 comments

Comments

@Vampire
Copy link
Contributor

Vampire commented Jan 7, 2019

The buildSrc project is an integral part of a build and it would be nice if your version checks could also be done there automatically.

As a manual workaround I thought about something along the lines of this you could use to get inspired:

task buildSrcDependencyUpdates(type: GradleBuild) {
    def dependencyUpdatesInitScript = file("$temporaryDir/dependencyUpdates-init.gradle")

    dir 'buildSrc'
    tasks = ['dependencyUpdates']
    startParameter.addInitScript dependencyUpdatesInitScript

    doFirst {
        dependencyUpdatesInitScript.text = '''
            rootProject {
                buildscript {
                    repositories {
                        gradlePluginPortal()
                    }

                    dependencies {
                        classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
                    }
                }

                apply plugin: 'com.github.ben-manes.versions'
            }
        '''.stripIndent().trim()
    }
}
dependencyUpdates.dependsOn buildSrcDependencyUpdates

Unfortunately it does not work.
I guess the problem is because the project script classpath cannot be modified at the point the closure is applied (reported at gradle/gradle#8173 as the error is not really meaningful).

So I'd say the best chance to nicely support this is, if you either add a second plugin class that implements Plugin<Gradle>, or changing the existing plugin class to implement Plugin<PluginAware> which would cover both (and Settings actually).

Then I think you could do something along the lines of

task buildSrcDependencyUpdates(type: GradleBuild) {
    def dependencyUpdatesInitScript = file("$temporaryDir/dependencyUpdates-init.gradle")

    dir 'buildSrc'
    tasks = ['dependencyUpdates']
    startParameter.addInitScript dependencyUpdatesInitScript

    doFirst {
        dependencyUpdatesInitScript.text = '''
            initscript {
                repositories {
                    gradlePluginPortal()
                }

                dependencies {
                    classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
                }
            }

            apply plugin: com.github.benmanes.gradle.versions.VersionsInitPlugin
        '''.stripIndent().trim()
    }
}
dependencyUpdates.dependsOn buildSrcDependencyUpdates

Of course it needs some more love, like

  • injecting the own version
  • injecting the resolutionStrategy
  • optimally not print the output, but generate the JSON or whatever and incorporate it into the main result as buildSrc sub-result with an own section in the default reports
  • ...

As a manual work-around I have now applied and configured the plugin manually on the buildSrc build and added

task buildSrcDependencyUpdates(type: GradleBuild) {
    dir 'buildSrc'
    tasks = ['dependencyUpdates']
}
dependencyUpdates.dependsOn buildSrcDependencyUpdates

to the parent build, so I just now get two reports, but having this nicely integrated and automatic would be much nicer of course.

@Vampire
Copy link
Contributor Author

Vampire commented Jan 7, 2019

Ah, louis showed the way to go without having to change the plugin class implementation or interface:

task buildSrcDependencyUpdates(type: GradleBuild) {
    def dependencyUpdatesInitScript = file("$temporaryDir/dependencyUpdates-init.gradle")

    dir 'buildSrc'
    tasks = ['dependencyUpdates']
    startParameter.addInitScript dependencyUpdatesInitScript

    doFirst {
        dependencyUpdatesInitScript.text = '''
            import com.github.benmanes.gradle.versions.VersionsPlugin

            initscript {
                repositories {
                    gradlePluginPortal()
                }

                dependencies {
                    classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
                }
            }

            rootProject {
                apply plugin: VersionsPlugin
            }
        '''.stripIndent().trim()
    }
}
dependencyUpdates.dependsOn buildSrcDependencyUpdates

My other points about resolutionStrategy, version injection and so on are still true of course.

@pkubowicz
Copy link
Contributor

pkubowicz commented Apr 26, 2021

This issue blocks projects from applying good practices of sharing build logic between subprojects (i.e., convention plugins).

Gradle currently suggests to stop putting all your plugins into the root build.gradle and instead create your own plugins in buildSrc/ that apply what is needed. This means that an officially recommended good practice is a blind spot of this plugin.

If you have your build structured as in Applying an external plugin in precompiled script plugin then gradle-versions-plugin won't check SpotBugs at all.

@jinganix
Copy link

jinganix commented Jun 17, 2021

I also ran into this problem.

So I extract dependencies from buildSrc/build.gradle.kts, and put them into one subproject.

https://github.com/linqu-tech/webpb/pull/24/files

Just provide an idea.

@PawelLipski
Copy link

+1 for this issue... for yet another simple workaround, see VirtusLab/git-machete-intellij-plugin#1013 (basically, treat buildSrc/ as if it was a top-level project)

PawelLipski added a commit to VirtusLab/git-machete-intellij-plugin that referenced this issue Jul 29, 2022
PawelLipski added a commit to VirtusLab/git-machete-intellij-plugin that referenced this issue Jul 29, 2022
PawelLipski added a commit to VirtusLab/git-machete-intellij-plugin that referenced this issue Aug 1, 2022
PawelLipski added a commit to VirtusLab/git-machete-intellij-plugin that referenced this issue Aug 1, 2022
PawelLipski added a commit to VirtusLab/git-machete-intellij-plugin that referenced this issue Aug 1, 2022
@mkondratek
Copy link

+1, it would be very handy 🙏

@mirfatif
Copy link

mirfatif commented May 6, 2024

gradle/gradle#14064 (comment)

You also need to set buildName:

tasks.register<GradleBuild>("buildSrcDependencyUpdates") {
  dir = File(rootDir, "buildSrc")
  tasks = mutableListOf("dependencyUpdates")
  buildName = "buildSource"
}

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

6 participants