Home > Mobile >  Import common task properties to build.gradle
Import common task properties to build.gradle

Time:12-02

We have several libraries that have common task configurations, I'd like to break these out into a Gradle plugin, rather than have them duplicated into every repo. Is there a way to do this? I can't find anything in the docs.

Current state:
(this exists in all repos)

jar {
    manifest {
        attributes(
                'OS': "${System.getProperty('os.name')}"
                // many more things here

        )
    }
}

Desired state:

  • central repo with plugin defined
  • each repo just imports the plugin to get the jar task
plugins {
    id 'my-custom-plugin'
}

Would also be okay with doing:

apply from: 'other.gradle'

but the other.gradle would need to live in a central repository.

CodePudding user response:

What you are describing is a convention plugin, the best resource showing how to set one up is in this video https://youtu.be/XnVZdMROVG8

There's also a couple of examples in the documentation, IE:

https://docs.gradle.org/current/samples/sample_convention_plugins.html https://docs.gradle.org/current/samples/sample_publishing_convention_plugins.html

But the video (all of them in that channel are worth watching) is the best imho

  • Related