Adam Jarvis
Adam Jarvis

Reputation: 73

Using local gradle plugin in a composite build, using groovy convention scripts

Trying to move from groovy conventions being in the buildSrc directory, into a composite build instead. In the project, is a library and a java gradle plugin. Both of which are published and build as their own modules.

Instead of using a pre-compiled groovy script in buildSrc, I was hoping to store some groovy config in it's own module. Then use includeBuild to bring it in as needed.

I have the following project structure in gradle:

project/
├─ custom-java-plugin/
│  ├─ main/
│  │  ├─ java/
│  │  │  ├─ Plugin.java
│  ├─ build.gradle
├─ some-lib/
│  ├─ build.gradle
├─ groovy-plugin/
│  ├─ main/
│  │  ├─ groovy/
│  │  │  ├─ my.convention.gradle
│  ├─ build.gradle
├─ build.gradle
├─ settings.gradle

I want to apply the custom-java-plugin within the my.convention.gradle groovy plugin. I've tried the following in my.convention.gradle;

plugins {
    id 'java-library'
    id 'custom-java-plugin'
    id 'maven-publish'
}

When I try to apply this to some-lib I get the error that gradle cannot find the custom-java-plugin

It is setup to be included in the root settings.gradle:

pluginManagement {
    repositories {
        mavenLocal()
    }
    includeBuild('custom-java-plugin')
}

rootProject.name = 'root'

// Plugin setup
includeBuild('custom-java-plugin')
includeBuild('groovy-plugin')

include('some-lib')

What am I missing here? I don't see why my library can see the groovy-plugin via includeBuild, but the groovy plugin can't see the compiled java plugin.

Upvotes: 2

Views: 1570

Answers (1)

Leonard Brünings
Leonard Brünings

Reputation: 13242

Have a look at the gradle build itself. You can see that there is build-logic and build-logic-commons, both with their own settings.gradle.kts. build-logic-commons is included twice, once in the ./settings.gradle.kts and once in the ./build-logic/settings.gradle.kts. This is necessary if you want to use its plugins in both build-logic and the main project.

I'd suggest to follow this convention, i.e., put plugins used only for the main build in build-logic and plugins used by other plugins as well as the main build into build-logic-commons.

Upvotes: 2

Related Questions