Hello together
I want to setup a multi project build, and having some trouble understanding how to do it the right way.
My project structure is like this:
projectA
|
├── subproject1
| └── build.gradle
├── subproject2
| └── build.gradle
|
├── build.gradle
└── settings.gradle
I have similiar projects like “projectA” with the same structure, so I want to use some kind of “shared/common” settings.gradle and/or build.gradle where can I defined common properties and plugins used in all projects.
It should only act as a kind of “template”. The projects themselves are distinct and I don’t want them to build from that “common” configs.
parent
|
├── common
| ├── build.gradle
| └── settings.gradle
|
├── projectA
| └── …
└── projectB
└── …
what I have so far:
common/build.gradle
subprojects {
apply plugin: 'com.test.DemoPlugin'
// some project-wide default plugin settings
demoPlugin {
outputFolder = '/tmp'
}
}
}
common/settings.gradle:
// this is only to speed up development, later it's going to be an
// exported Jar file included as dependency
includeBuild('D:/Development/intellij/workspace/GradleTest/DemoPlugin')
projectA/build.gradle
plugins {
id 'com.example.DemoPlugin' apply false
}
apply from: 'common/build.gradle'
subprojects {
demoPlugin {
// set another property in this plugin for all sub-projects
property1 = '123'
}
}
projectA/settings.gradle
rootProject.name = 'projectA'
apply from: 'common/settings.gradle'
It works this way, but I also want to move that plugin { } block into the common files (build or settings.gradle). If I do so, I’m getting this error:
common\build.gradle’: 6: Only Project and Settings build scripts can contain plugins {} blocks
Am I on the right track or do I have to solve it completely different ?
I just want to have a “common template” between (technically independent) projects which I can re-use.