-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Settings plugin (configure project structure) / meta plugins
- Loading branch information
Showing
13 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id("org.gradlex.build-parameters") version "1.4.3" | ||
} | ||
|
||
group = "org.example" | ||
|
||
buildParameters { | ||
pluginId("org.example.build-parameters") | ||
bool("ci") { | ||
defaultValue.set(false) | ||
fromEnvironment() | ||
} | ||
group("catalina") { | ||
string("home") { | ||
fromEnvironment() | ||
description.set("Root of the Tomcat installation") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "org.example" |
8 changes: 8 additions & 0 deletions
8
...ta-plugins/plugin-analysis-plugins/src/main/kotlin/org.example.plugin-analysis.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import org.example.pluginanalysis.PluginApplicationOrderAnalysis | ||
|
||
tasks.register<PluginApplicationOrderAnalysis>("analysePluginApplicationOrder") { | ||
group = "help" | ||
|
||
pluginSrcFolders.from(subprojects.map { it.layout.projectDirectory.dir("src/main/kotlin") }) | ||
pluginApplicationDiagram.set(layout.buildDirectory.file("reports/plugins/plugin-application-order.puml")) | ||
} |
71 changes: 71 additions & 0 deletions
71
...ysis-plugins/src/main/kotlin/org/example/pluginanalysis/PluginApplicationOrderAnalysis.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.example.pluginanalysis | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.InputFiles | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
import java.io.File | ||
|
||
abstract class PluginApplicationOrderAnalysis : DefaultTask() { | ||
|
||
@get:InputFiles | ||
abstract val pluginSrcFolders : ConfigurableFileCollection | ||
|
||
@get:OutputFile | ||
abstract val pluginApplicationDiagram: RegularFileProperty | ||
|
||
@TaskAction | ||
fun analyse() { | ||
val pluginDependencies = pluginSrcFolders.associate { srcFolder -> | ||
val pluginProjectName = srcFolder.parentFile.parentFile.parentFile.name | ||
pluginProjectName to (srcFolder.listFiles() ?: emptyArray()).filter { | ||
it.name.endsWith(".gradle.kts") | ||
}.associate { pluginFile -> | ||
val pluginId = pluginFile.name.replaceFirst(".gradle.kts", "") | ||
val shortenedPluginId = shorten(pluginId) | ||
shortenedPluginId to pluginsBlock(pluginFile.readText()).lines().filter { it.contains("id(") }.map { | ||
shorten(it.substring(it.indexOf("id(\"") + 4, it.indexOf("\")"))) | ||
} | ||
} | ||
}.filter { it.value.isNotEmpty() } | ||
|
||
val lineBreak = "\n " | ||
pluginApplicationDiagram.get().asFile.writeText(""" | ||
@startuml | ||
${pluginDependencies.map { (projectName, pluginIds) -> | ||
"package \"$projectName\" {$lineBreak" + | ||
pluginIds.keys.joinToString("") { "agent \"$it\"$lineBreak" } + | ||
"$lineBreak}" | ||
}.joinToString(lineBreak)} | ||
${pluginDependencies.values.fold(emptyMap<String, List<String>>()) { a, b -> a + b }.filter { | ||
it.value.isNotEmpty() | ||
}.map { | ||
(from, to) -> to.joinToString("") { "\"$from\" --down--> \"$it\"$lineBreak" } | ||
}.joinToString(lineBreak)} | ||
@enduml | ||
""".trimIndent()) | ||
|
||
logger.lifecycle("Diagram: ${pluginApplicationDiagram.get().asFile.absolutePath}") | ||
} | ||
|
||
private fun pluginsBlock(script: String) = script.indexOf("}").let { | ||
when(it) { | ||
-1 -> "" | ||
else -> script.substring(0, it) | ||
} | ||
} | ||
|
||
private fun shorten(pluginId: String) = pluginId.split(".").let { segments -> | ||
when (segments.size) { | ||
1 -> segments.single() | ||
else -> segments.subList(0, segments.size - 1).map { it.first() } | ||
.joinToString(".", "", ".") + segments.last() | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
dependencies { | ||
implementation(project(":build-parameters-plugins")) | ||
implementation("com.gradle:gradle-enterprise-gradle-plugin:3.15.1") | ||
} |
19 changes: 19 additions & 0 deletions
19
...lugins/settings-plugins/src/main/kotlin/org.example.gradle-enterprise.settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import buildparameters.BuildParametersExtension | ||
|
||
plugins { | ||
// Use the Gradle Enterprise plugin to publish Build Scan to https://scans.gradle.com | ||
id("com.gradle.enterprise") | ||
id("org.example.build-parameters") | ||
} | ||
|
||
// Configure the Gradle Enterprise plugin | ||
gradleEnterprise { | ||
buildScan { | ||
// You may remove this check to publish build scans for every build (preferred, if there are no concerns) | ||
if (the<BuildParametersExtension>().ci) { | ||
publishAlways() | ||
} | ||
termsOfServiceUrl = "https://gradle.com/terms-of-service" | ||
termsOfServiceAgree = "yes" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...lugins/settings-plugins/src/main/kotlin/org.example.project-structure.settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Include all subfolders that contain a 'build.gradle.kts' as subprojects | ||
rootDir.listFiles()?.filter { File(it, "build.gradle.kts").exists() }?.forEach { subproject -> | ||
include(subproject.name) | ||
} |
22 changes: 22 additions & 0 deletions
22
...eta-plugins/settings-plugins/src/main/kotlin/org.example.repositories.settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pluginManagement { | ||
// Get community plugins from the Gradle Plugin Portal | ||
repositories.gradlePluginPortal() | ||
|
||
// Get our own convention plugins from 'gradle/plugins' | ||
if (File(rootDir, "gradle/plugins").exists()) { | ||
includeBuild("gradle/plugins") | ||
} | ||
// If not the main build, 'plugins' is located next to the build (e.g. gradle/settings) | ||
if (File(rootDir, "../plugins").exists()) { | ||
includeBuild("../plugins") | ||
} | ||
} | ||
|
||
dependencyResolutionManagement { | ||
// Get components from Maven Central | ||
repositories.mavenCentral() | ||
// In the main build, find the platform in 'gradle/platform' | ||
if (File(rootDir, "gradle/platform").exists()) { | ||
includeBuild("gradle/platform") | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...le/meta-plugins/settings-plugins/src/main/kotlin/org.example.settings.settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
plugins { | ||
id("org.example.gradle-enterprise") | ||
id("org.example.project-structure") | ||
id("org.example.repositories") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencyResolutionManagement { | ||
repositories.gradlePluginPortal() | ||
} | ||
|
||
include("build-parameters-plugins", "plugin-analysis-plugins", "settings-plugins") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id("org.example.plugin-analysis") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pluginManagement { | ||
includeBuild("../meta-plugins") | ||
} | ||
plugins { | ||
id("org.example.settings") | ||
} | ||
|
||
dependencyResolutionManagement { | ||
repositories.gradlePluginPortal() | ||
includeBuild("../meta-plugins") // for 'build-parameters' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
pluginManagement { | ||
includeBuild("gradle/meta-plugins") | ||
} | ||
plugins { | ||
id("org.example.settings") | ||
} | ||
|
||
rootProject.name = "gradle-project-setup-howto" |