Is there any way for other projects to use the gra...
# gradle
i
Is there any way for other projects to use the gradle plugin which is implemented inside the same root project?
e
No you can’t. It’s a chicken and egg problem, you need the build logic to build the plugin and you want to use the plugin in your build logic. 🍳 🐔 What you can do however is break the cycle by using two builds. You can use Gradle included builds to make it easy to work with such a setup. See https://docs.gradle.org/current/userguide/composite_builds.html and https://github.com/gradle/gradle/tree/master/subprojects/docs/src/snippets/compositeBuilds/plugin-dev
i
not sure how to use it, do i need to specifiy '"includeBuild " in settings.gradle ?
e
yes, that’s how composite builds work
I linked the documentation and a working sample, this should help you get started
i
Can you provide me more detail ? How I can change the configuration to use the local plugin ? for example, i tried the following but no luck rootProject.name = 'app' includeBuild('../plugin-library') { dependencySubstitution { substitute module('plugin-name') with project(':') } }
e
I don’t know the exact setup of your build. Please start from the sample. In most cases you don’t need any substitution and the default should work.
👍 2
c
Depending on what you’re doing, you might not need a full composite build. You can also implement custom Gradle build logic for a single project with
buildSrc
without the need for multiple repositories/builds https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources
i
does it support plugin developed from external dependencies? I have to included couples of other library to implement the plugin.
c
Yup! For example, adding
buildSrc/build.gradle.kts
with
Copy code
plugins {
    `kotlin-dsl`
}
repositories {
    jcenter()
}
dependencies {
    compile("org.yaml:snakeyaml:1.25")
}
adds SnakeYaml to the plugin classpath, and you can use that library from buildscript code in
buildSrc/src/main/kotlin
, and also from any of the normal Gradle scripts in your project. It’s effectively the same as an “included build”, but it’s already set up and available without any additional configuration/repos in every Gradle project.
i
sorry for so many question 🙂, does it support add jar files as well ?
e
buildSrc
is just a Gradle build so it supports the same
👍 1