I have an android project with multiple sub projec...
# community-support
l
I have an android project with multiple sub projects/modules which are configured via convention plugins. The convention plugins are provided by a composite build:
Copy code
includeBuild("./configuration-plugin")
In my android build I can apply the plugins like:
Copy code
plugins {
    id("de.mycompany.configuration.scripts.android.application")
}
The package structure of my composite build where the convention plugins rely is
de.mycopnay.configuration.scripts...(e.g. android-application.kts)
. Is it possible to shorten the name without changing the package structure, so i can apply the plugins as:
Copy code
plugins {
    id("convention.android.application")
}
v
You could just declare an additional plugin ID that points to the same plugin class as the automatic plugin id
l
I'm not aware of this approach so I had to ask ChatGPT and got:
Copy code
1. Inside your buildSrc or composite build project, create a directory structure following this pattern: src/main/resources/META-INF/gradle-plugins.

2. Create a properties file named after your desired additional plugin ID. For example, for the ID de.mycompany.configuration.scripts.android-application, you would create a file named de.mycompany.configuration.scripts.android-application.properties.

3. In that properties file, specify the implementation-class property that points to the generated class name of your precompiled script plugin. This can be tricky with precompiled script plugins, as the implementation class is generated by Gradle. For precompiled scripts, the class name typically follows the pattern org.gradle.kotlin.dsl.<file-name-without-extension>, but you may need to inspect the build output to determine the exact class name.
Is this waht you mean or can I achieve it another (maybe better) way
Or can I handle it via:
Copy code
gradlePlugin {
    plugins {
        create("myPlugins") {
            id = "my-plugin"
            implementationClass = "my.MyPlugin"
        }
    }
}
where implementationClass points to the generated plugin class in the /build folder?
t
Add a
convention.android.application.gradle.kts
that contains:
Copy code
plugins {
  id("de.mycompany.configuration.scripts.android.application")
}
?
l
ok then I would have to put it in the composite build under
src/kotlin/convention.android.application.gradle.kts
right?
v
I'm not aware of this approach so I had to ask ChatGPT and got:
Please be aware, that ChatGPT (and all similar AI tools) is perfectly fine in giving answers that look correct, but utterly bad in giving answers that are correct. They are pretty unsuitable to answer questions you don't know the answer of already. They are great to do stuff you are too lazy to do (the good kind of lazy, not the bad one) as you have to understand what it gives you, remove the non-sense and make it work properly. What it told you can be done yes, but doing it in
buildSrc
when you already have an included build is pretty much non-sense. What I meant was what you wrote second which then effectively creates that file on-the-fly, but you can of course also create the file in
src/main/resources
manually in your plugin project. What Thomas said is also one variation, it does not simply create a second ID for the new plugin, but creates a whole new plugin that applies the other one. Use whatever you like more. 🙂 And yes, if you go the second-plugin approach, naming the file
src/kotlin/convention.android.application.gradle.kts
and not having a package statement is one option. Naming it
application.gradle.kts
with package statement
convention.android
would be another.
❤️ 1
Btw.
my-plugin
concretely is a bad idea, all non-built-in plugins should be namespaced, i. e. contain at least one dot. IDs without dot should stay reserved for built-in plugins, then you are also sure that there will not be a name clash in a newer Gradle version.
❤️ 1
l
Thank you for this detailed answer. I have a follow-up question: is it possible to control which convention plugin is exposed. For example, some of my convention plugins are shared between the "primary" convention plugins which should be exposed while the shared one shouldn't be visible for my consumer projects
v
I guess when you say convention plugin you actually mean precompiled script plugin? Do you publish those plugins or do the consumers use your plugins via composite build?
l
Exactly. I consume them via composite build
v
Then probably not
l
ok thank you