How to use plugin-subproject in another subproject?

I have similar project structure:

-root
    -sub-lib
    -sub-gradle-plugin
    -sub-demo-app

sub-gradle-plugin is a binary plugin. And I want it to use in demo-app project for testing/developing. So, as for now I’m used to publish plugin to local maven repo and thus have this in setting file to be able to fetch plugin from sub-demo-app:

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven("maven-local")
    }
} 

Each time I make a change into plugin, I have to publish it first to local folder, and only then it updates in demo-app. But, can I link this plugin to demo-app-project like I do, for example for library sub-lib project ? That is use direct dependency to a gradle project.

dependencies {
     implementation(project(":sub-lib"))
}

You need to use a composite build to do this.

See

So, in your example gradle-plugin isn’t a part of the same root project. it’s a separate project that doesn’t share common configuration. and doc says:
must not have a rootProject.name the same as another included build.

So, in your example gradle-plugin isn’t a part of the same root project.

Correct, there’s two root project’s but they act like a single project thanks to Gradle’s Composite Build feature

I’ve been thinking that the point around Composite Build is that we could link to exactly separate project as would it be our own subproject. is it just another workaround here ?

Using a locally built gradle plugin in your build is different from using one java project in another. There’s a chicken or egg problem where the buildscript classloader needs to be defined before the plugin is built.

For this reason, you need a separate root project for the plugin which is built before the client project’s buildscript classloader is defined.

Luckily, the composite build feature makes it behave as if its a multi module build for the most part.

1 Like

Oh, yes. Thank you, I got the point. I’ll try this way. But Composite Build seems aren’t supposed to share common config, yes ?

subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")

repositories {
    jcenter()
}

dependencies {
    "implementation"(platform("org.jetbrains.kotlin:kotlin-bom"))
    "implementation"("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}

tasks {
    withType<KotlinCompile> {
        kotlinOptions.apiVersion = "1.3"
        kotlinOptions.languageVersion = "1.3"
        kotlinOptions.jvmTarget = "1.8"
    }
}

You could use a commom.gradle which you apply in both. See my version.txt logic where I share the version number between the two builds

One thing I forgot to ask is this: Do you intend to publish this plugin for use in multiple projects? Or do you only need it inside a single (multi module?) project?

If you don’t intend to publish the plugin, you can simply put the plugin code in the “buildSrc” project

Yes, I intend. At least, I want to try :smile:
Eventually I came to decision not to use composite build (as for now). It complicates config-sharing and, additionally, gradle-plugin-subproject has two direct dependencies on its co-projects. It would be simpler to keep them together.

dependencies {
    runtimeOnly(project(":launcher-app"))
    implementation(project(":manifest-lib"))
}

And now I’m wondering if it’s possible to include these two in gradle plugin publication that java-gradle-plugin creates for publishing in order not to publish them separately.