paskos
paskos

Reputation: 759

How to apply org.gradle.toolchains.foojay-resolver-convention plugin to custom gradle distribution?

We have hundreds of gradle projects using toolchains sdk automatic download on gradle 7.6.2 accross our organisation. We also have a custom gradle distribution that we provide to all the teams.

Gradle 8 Upgrade instructions says

Using automatic toolchain downloading without having a repository configured Automatic toolchain downloading without explicitly providing repositories to use is no longer supported. See user manual for more information.

We don't want to force tens of teams to have to manually add

plugins {
    id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}

to hundreds of settings.gradle files and to have to manage the update of the version. Since we'll already provide a custom gradle distribution for gradle 8.3 and since it contains an init.gradle script to setup some global variables. We would like to apply the convention in the init.gradle.

I tried unsuccessfully to apply org.gradle.toolchains.foojay-resolver-convention in our init.gradle I also tried applying the plugin through its class name directly. I searched the internet and read gradle code.

I managed to add foojay-resolver-0.7.0.jar inside the distribution gradle-8.3/lib/plugins directory.

Once the wrapper runs I can see it in ~/.gradle/wrapper/dists/our-distribution-dir/generated-cache-dir/gradle-8.3/lib/plugins alongside gradle-plugins-8.3.jar

I'm pretty sure there is a way to achieve this. I just haven't found it.

When I try with class name

settingsEvaluated { settings ->
    settings.pluginManagement {
        repositories {
            maven {
                url repoUrl
            }
        }
    }

    settings.apply plugin: 'org.gradle.toolchains.foojay.FoojayToolchainsConventionPlugin'
}

I get

> Could not get unknown property 'org' for build of type org.gradle.invocation.DefaultGradle.


When I try with plugin id

settingsEvaluated { settings ->
    settings.pluginManagement {
        repositories {
            maven {
                url repoUrl
            }
        }
    }

    settings.apply plugin: 'org.gradle.toolchains.foojay-resolver-convention'
}

I get

Plugin with id 'org.gradle.toolchains.foojay-resolver-convention' not found.

Thanks in advance

Upvotes: 1

Views: 2038

Answers (1)

bvp
bvp

Reputation: 1

in init.gradle

beforeSettings { settings ->
  settings.buildscript.repositories {
    maven {
      url '...'
    }
  }
  settings.buildscript.dependencies {
    classpath("org.gradle.toolchains:foojay-resolver:0.8.0")
  }
}

settingsEvaluated { settings ->
  settings.apply plugin: 'org.gradle.toolchains.foojay-resolver-convention'
  settings.pluginManagement {
    repositories {
      maven {
        url '...'
      }
    }
  }
}

Upvotes: 0

Related Questions