Skip to content

Commit 5333745

Browse files
committed
slide publish
1 parent d6114e6 commit 5333745

File tree

8 files changed

+249
-1
lines changed

8 files changed

+249
-1
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-logic/convention/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@ gradlePlugin {
3939
id = "net.kwmt27.jetpackcomposeplayground.library"
4040
implementationClass = "AndroidLibraryConventionPlugin"
4141
}
42+
register("publish") {
43+
id = "com.github.kwmt.publish"
44+
implementationClass = "PublishPlugin"
45+
}
4246
}
4347
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// import org.gradle.api.Plugin
2+
// import org.gradle.api.Project
3+
// import org.gradle.api.artifacts.ProjectDependency
4+
// import java.util.Locale
5+
//
6+
// class ProjectDependencyGraphPlugin : Plugin<Project> {
7+
// override fun apply(target: Project) {
8+
// // from: https://github.com/JakeWharton/SdkSearch/blob/3351cad9bfacb0a364858e843774147143f58c7a/gradle/projectDependencyGraph.gradle
9+
// // you need to command `brew install graphviz`
10+
// with(target) {
11+
// task("projectDependencyGraph") {
12+
// doLast {
13+
// val dot = rootProject.buildDir.resolve("reports/dependency-graph/project.dot")
14+
// dot.parentFile.mkdirs()
15+
// dot.delete()
16+
//
17+
// dot.writeText("digraph {\n")
18+
// dot.appendText(" graph [label=\"${rootProject.name}\\n \",labelloc=t,fontsize=30,ranksep=1.4];\n")
19+
// dot.appendText(" node [style=filled, fillcolor=\"#bbbbbb\"];\n")
20+
// dot.appendText(" rankdir=TB;\n")
21+
// val rootProjects = mutableListOf(rootProject)
22+
// val queue: MutableList<Project> = mutableListOf(rootProject)
23+
//
24+
// while (queue.isNotEmpty()) {
25+
// val project = queue.removeAt(0)
26+
// rootProjects.add(project)
27+
// queue.addAll(project.childProjects.values)
28+
// }
29+
// var projects = mutableSetOf<Project>()
30+
// val dependencies = mutableMapOf<Pair<Project, Project>, List<String>>()
31+
// val multiplatformProjects = mutableListOf<Project>()
32+
// val jsProjects = mutableListOf<Project>()
33+
// val androidProjects = mutableListOf<Project>()
34+
// val javaProjects = mutableListOf<Project>()
35+
//
36+
// queue.add(rootProject)
37+
// while (queue.isNotEmpty()) {
38+
// val project = queue.removeAt(0)
39+
// queue.addAll(project.childProjects.values)
40+
//
41+
// if (project.plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
42+
// multiplatformProjects.add(project)
43+
// }
44+
// if (project.plugins.hasPlugin("kotlin2js")) {
45+
// jsProjects.add(project)
46+
// }
47+
// if (project.plugins.hasPlugin("com.android.library") || project.plugins.hasPlugin(
48+
// "com.android.application"
49+
// )
50+
// ) {
51+
// androidProjects.add(project)
52+
// }
53+
// if (project.plugins.hasPlugin("java-library") || project.plugins.hasPlugin("java")) {
54+
// javaProjects.add(project)
55+
// }
56+
//
57+
// project.configurations.forEach { config ->
58+
// config.dependencies
59+
// .withType(ProjectDependency::class.java)
60+
// .forEach { dependency ->
61+
// val graphKey = Pair(project, dependency.dependencyProject)
62+
// projects.add(project)
63+
// projects.add(dependency.dependencyProject)
64+
// rootProjects.remove(dependency.dependencyProject)
65+
// val traits =
66+
// dependencies.computeIfAbsent(graphKey) { mutableListOf<String>() }
67+
// .toMutableList()
68+
//
69+
// if (config.name.lowercase().endsWith("implementation")) {
70+
// traits.add("style=dotted")
71+
// }
72+
// }
73+
// }
74+
// }
75+
//
76+
// projects = projects.sortedBy { it.path }.toHashSet()
77+
//
78+
// dot.appendText("\n # Projects\n\n")
79+
// for (project in projects) {
80+
// val traits = mutableListOf<String>()
81+
//
82+
// if (rootProjects.contains(project)) {
83+
// traits.add("shape=box")
84+
// }
85+
//
86+
// if (multiplatformProjects.contains(project)) {
87+
// traits.add("fillcolor=\"#ffd2b3\"")
88+
// } else if (jsProjects.contains(project)) {
89+
// traits.add("fillcolor=\"#ffffba\"")
90+
// } else if (androidProjects.contains(project)) {
91+
// traits.add("fillcolor=\"#baffc9\"")
92+
// } else if (javaProjects.contains(project)) {
93+
// traits.add("fillcolor=\"#ffb3ba\"")
94+
// } else {
95+
// traits.add("fillcolor=\"#eeeeee\"")
96+
// }
97+
//
98+
// dot.appendText(" \"${project.path}\" [${traits.joinToString(", ")}];\n")
99+
// }
100+
//
101+
// dot.appendText("\n {rank = same;")
102+
// for (project in projects) {
103+
// if (rootProjects.contains(project)) {
104+
// dot.appendText(" \"${project.path}\";")
105+
// }
106+
// }
107+
// dot.appendText("}\n")
108+
//
109+
// dot.appendText("\n # Dependencies\n\n")
110+
// dependencies.forEach { (key, traits) ->
111+
// dot.appendText(" \"${key.first.path}\" -> \"${key.second.path}\"")
112+
// if (traits.isNotEmpty()) {
113+
// dot.appendText(" [${traits.joinToString(", ")}]")
114+
// }
115+
// dot.appendText("\n")
116+
// }
117+
//
118+
// dot.appendText("}\n")
119+
// val p = ProcessBuilder("dot", "-Tpng", "-O", "project.dot").start()
120+
// p.waitFor()
121+
// if (p.exitValue() != 0) {
122+
// throw RuntimeException(p.errorStream.toString())
123+
// }
124+
//
125+
// println("Project module dependency graph created at ${dot.absolutePath}.png")
126+
// }
127+
// }
128+
// }
129+
// }
130+
// }
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import com.android.build.api.dsl.LibraryExtension
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
import org.gradle.api.publish.PublishingExtension
5+
import org.gradle.api.publish.maven.MavenPublication
6+
import org.gradle.kotlin.dsl.configure
7+
import org.gradle.kotlin.dsl.get
8+
import org.gradle.kotlin.dsl.register
9+
import java.util.Locale
10+
11+
interface PublishPluginExtension {
12+
companion object {
13+
const val DEFAUlT_DIEMNSION = "io.github.kwmt.slide.default"
14+
}
15+
}
16+
17+
class PublishPlugin : Plugin<Project> {
18+
override fun apply(target: Project) {
19+
with(target) {
20+
with(pluginManager) {
21+
apply("maven-publish")
22+
apply("com.android.library")
23+
}
24+
25+
configure<LibraryExtension> {
26+
publishing {
27+
buildTypes.all {
28+
val buildType = this.name
29+
productFlavors.all {
30+
val flavor = this.name
31+
singleVariant("${flavor}${buildType.replaceFirstChar {
32+
if (it.isLowerCase()) it.titlecase(
33+
Locale.getDefault()
34+
) else it.toString()
35+
}}")
36+
}
37+
singleVariant(buildType)
38+
}
39+
// singleVariant("productionRelease") {
40+
// withSourcesJar()
41+
// }
42+
}
43+
}
44+
45+
configure<PublishingExtension> {
46+
publications {
47+
register<MavenPublication>("productionRelease") {
48+
groupId = "io.my-company"
49+
artifactId = "my-library"
50+
version = "1.0.3"
51+
afterEvaluate {
52+
components.forEach {
53+
println("----- ${it.name}")
54+
}
55+
from(components["productionRelease"])
56+
}
57+
}
58+
// register<MavenPublication>("stagingRelease") {
59+
// groupId = "io.my-company"
60+
// artifactId = "my-library-staging"
61+
// version = "1.0"
62+
// afterEvaluate {
63+
// components.forEach {
64+
// println("----- ${it.name}")
65+
// }
66+
// from(components["stagingRelease"])
67+
// }
68+
// }
69+
repositories {
70+
maven {
71+
name = "myRepo"
72+
url = uri(layout.buildDirectory.dir("repo"))
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}

feature/samples/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@ plugins {
44
}
55
android {
66
namespace = "net.kwmt27.jetpackcomposeplayground.feature.samples"
7+
8+
flavorDimensions += listOf("default")
9+
productFlavors {
10+
register("exposed") {
11+
dimension = "default"
12+
}
13+
register("paid") {
14+
dimension = "default"
15+
}
16+
register("free") {
17+
dimension = "default"
18+
}
19+
}
720
}
821

22+
923
dependencies {
1024
implementation(projects.core.ui)
1125
implementation(libs.androidx.core.ktx)
@@ -24,4 +38,6 @@ dependencies {
2438

2539
implementation(libs.coil.compose)
2640
implementation(libs.coil.gif)
41+
42+
implementation("io.my-company:my-library:1.0")
2743
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ jetpackcomposeplayground-android-application = { id = "net.kwmt27.jetpackcompose
5757
jetpackcomposeplayground-android-library = { id = "net.kwmt27.jetpackcomposeplayground.library", version = "unspecified" }
5858
jetpackcomposeplayground-android-application-compose = { id = "net.kwmt27.jetpackcomposeplayground.application.compose", version = "unspecified" }
5959
jetpackcomposeplayground-android-library-compose = { id = "net.kwmt27.jetpackcomposeplayground.library.compose", version = "unspecified" }
60+
com-github-kwmt-publish = { id = "com.github.kwmt.publish", version = "unspecified" }
6061
[bundles]
6162

settings.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ dependencyResolutionManagement {
1515
gradlePluginPortal()
1616
google()
1717
mavenCentral()
18+
// mavenLocal()
19+
maven {
20+
url = uri("/Users/kwmt/personal/dev/JetpackComposePlayGround/slide/build/repo")
21+
}
1822
}
1923
}
2024

slide/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
plugins {
22
alias(libs.plugins.jetpackcomposeplayground.android.library)
33
alias(libs.plugins.jetpackcomposeplayground.android.library.compose)
4+
alias(libs.plugins.com.github.kwmt.publish)
45
}
56

67
android {
78
namespace = "com.github.kwmt.slide"
9+
val defaultDimension = PublishPluginExtension.DEFAUlT_DIEMNSION
10+
flavorDimensions += listOf(defaultDimension)
11+
productFlavors {
12+
register("develop") {
13+
dimension = defaultDimension
14+
}
15+
register("staging") {
16+
dimension = defaultDimension
17+
}
18+
register("production") {
19+
dimension = defaultDimension
20+
}
21+
}
822
}
923

1024
dependencies {

0 commit comments

Comments
 (0)