Skip to content

Commit 61c8f59

Browse files
committed
add maven central repo and script for publication
1 parent acdc91c commit 61c8f59

File tree

9 files changed

+175
-16
lines changed

9 files changed

+175
-16
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Compiler plugin Build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
15+
steps:
16+
17+
- name: Checkout branch
18+
uses: actions/checkout@v4
19+
20+
- name: set up JDK 21
21+
uses: actions/setup-java@v3
22+
with:
23+
java-version: '21'
24+
distribution: 'temurin'
25+
cache: gradle
26+
27+
- name: Grant execute permission for gradlew
28+
run: chmod +x gradlew
29+
30+
- name: build app with compiler plugin
31+
run: ./gradlew :compiler-plugin build

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
/captures
1111
.externalNativeBuild
1212
.cxx
13-
local.properties
13+
local.properties
14+
/.gnupg

app/build.gradle.kts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ android {
2828
}
2929

3030
dependencies {
31-
implementation(project(":compiler-plugin"))
32-
"kotlinCompilerPluginClasspath"(project(":compiler-plugin"))
31+
implementation(libs.stslex.compilerPlugin)
32+
kotlinCompilerPluginClasspath(libs.stslex.compilerPlugin)
3333

3434
coreLibraryDesugaring(libs.android.desugarJdkLibs)
3535
implementation(libs.androidx.activity)
@@ -38,9 +38,3 @@ dependencies {
3838
implementation(libs.androidx.lifecycle.common)
3939
implementation(libs.androidx.constraintlayout)
4040
}
41-
42-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
43-
kotlinOptions {
44-
freeCompilerArgs += listOf("-Xplugin=${rootProject.projectDir}/compiler-plugin-lib/build/libs/compiler-plugin-lib.jar")
45-
}
46-
}

app/src/main/kotlin/com/stslex/compiler_app/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import androidx.lifecycle.lifecycleScope
99
import com.stslex.compiler_app.UserToastUtil.sendToastOfUserChanges
1010
import com.stslex.compiler_app.app.R
1111
import com.stslex.compiler_app.model.UserModel
12-
import com.stslex.compiler_plugin_lib.DistinctUntilChangeFun
12+
import io.github.stslex.compiler_plugin.DistinctUntilChangeFun
1313
import kotlinx.coroutines.flow.launchIn
1414
import kotlinx.coroutines.flow.onEach
1515
import java.util.logging.Level

compiler-plugin/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/build
2-
*.pom
2+
*.pom
3+
/.gnupg
4+
/gradle.properties

compiler-plugin/build.gradle.kts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import java.security.MessageDigest
2+
13
plugins {
24
`java-library`
5+
`maven-publish`
6+
signing
37
alias(libs.plugins.jetbrains.kotlin.jvm)
48
}
59

10+
group = "io.github.stslex"
11+
version = "0.0.1"
12+
613
java {
714
sourceCompatibility = JavaVersion.VERSION_21
815
targetCompatibility = JavaVersion.VERSION_21
@@ -20,3 +27,124 @@ dependencies {
2027
compileOnly(libs.jetbrains.kotlin.compiler.embeddable)
2128
}
2229

30+
tasks.register<Jar>("javadocJar") {
31+
archiveClassifier.set("javadoc")
32+
}
33+
34+
tasks.register<Jar>("sourcesJar") {
35+
archiveClassifier.set("sources")
36+
from(sourceSets["main"].allSource)
37+
}
38+
39+
publishing {
40+
publications {
41+
create<MavenPublication>("mavenJava") {
42+
from(components["java"])
43+
44+
groupId = "io.github.stslex"
45+
artifactId = "compiler-plugin"
46+
version = "0.0.1"
47+
48+
artifact(tasks["javadocJar"])
49+
artifact(tasks["sourcesJar"])
50+
suppressPomMetadataWarningsFor("runtime")
51+
52+
pom {
53+
name.set("My Kotlin Compiler Plugin")
54+
description.set("A custom Kotlin compiler plugin for experimentation")
55+
url.set("https://github.com/stslex/compiler_plugin_workshow")
56+
licenses {
57+
license {
58+
name.set("The Apache License, Version 2.0")
59+
url.set("https://raw.githubusercontent.com/stslex/compiler_plugin_workshow/refs/heads/publish_maven/LICENSE")
60+
}
61+
}
62+
developers {
63+
developer {
64+
id.set("stslex")
65+
name.set("Ilya")
66+
email.set("ilya977.077@gmail.com")
67+
}
68+
}
69+
scm {
70+
connection.set("scm:git:git://github.com/stslex/compiler_plugin_workshow.git")
71+
developerConnection.set("scm:git:ssh://github.com:stslex/compiler_plugin_workshow.git")
72+
url.set("https://github.com/stslex/compiler_plugin_workshow")
73+
}
74+
}
75+
}
76+
}
77+
}
78+
79+
signing {
80+
sign(publishing.publications["mavenJava"])
81+
}
82+
83+
val localRepoPath = File(
84+
"${System.getProperty("user.home")}/.m2/repository/io/github/stslex/compiler-plugin/$version"
85+
)
86+
87+
tasks.named("publishToMavenLocal") {
88+
finalizedBy(generateChecksums)
89+
finalizedBy(packageArtifacts)
90+
}
91+
92+
val generateChecksums = tasks.register("generateChecksums") {
93+
group = "publishing"
94+
description = "Generate MD5 и SHA1 for all artifacts in local repository"
95+
96+
doLast {
97+
if (!localRepoPath.exists()) {
98+
error("❌ Local repository not found: $localRepoPath")
99+
}
100+
101+
val artifacts = localRepoPath.listFiles { file ->
102+
file.isFile &&
103+
file.name.endsWith(".md5").not() &&
104+
file.name.endsWith(".sha1").not()
105+
}
106+
107+
if (artifacts.isNullOrEmpty()) error("❌ No artifacts found in local repository: $localRepoPath")
108+
109+
artifacts.forEach { file ->
110+
val md5File = File(file.parent, "${file.name}.md5")
111+
val sha1File = File(file.parent, "${file.name}.sha1")
112+
113+
md5File.writeText(file.md5Hex())
114+
sha1File.writeText(file.sha1Hex())
115+
116+
println("✅ Checksums are generated: ${md5File.name}, ${sha1File.name}")
117+
}
118+
}
119+
}
120+
121+
val packageArtifacts = tasks.registering(Zip::class) {
122+
group = "publishing"
123+
description = "Create ZIP-archive with artifacts for Central Publisher Portal"
124+
125+
val localRepo = file(localRepoPath)
126+
127+
if (localRepo.exists().not()) error("Local repo not found: $localRepo")
128+
129+
from(localRepo) {
130+
into("io/github/stslex/compiler-plugin/$version/")
131+
include("**/*.jar", "**/*.pom", "**/*.asc", "**/*.md5", "**/*.sha1")
132+
exclude("*.module")
133+
exclude("*.module.*")
134+
}
135+
136+
archiveFileName.set("compiler-plugin-${version}.zip")
137+
destinationDirectory.set(layout.buildDirectory.dir("distributions"))
138+
}
139+
140+
fun File.md5Hex(): String = inputStream().use { stream ->
141+
MessageDigest.getInstance("MD5")
142+
.digest(stream.readBytes())
143+
.joinToString("") { "%02x".format(it) }
144+
}
145+
146+
fun File.sha1Hex(): String = inputStream().use { stream ->
147+
MessageDigest.getInstance("SHA-1")
148+
.digest(stream.readBytes())
149+
.joinToString("") { "%02x".format(it) }
150+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ kotlin.code.style=official
2020
# Enables namespacing of each library's R class so that its R class includes only the
2121
# resources declared in the library itself and none from the library's dependencies,
2222
# thereby reducing the size of the R class for that library
23-
android.nonTransitiveRClass=true
23+
android.nonTransitiveRClass=true

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ activity = "1.10.0"
1414
constraintLayout = "2.2.0"
1515
jetbrainsKotlinJvm = "2.0.20"
1616

17+
stslexCompilerPlugin = "0.0.1"
18+
1719
[libraries]
1820
android-desugarJdkLibs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }
1921

@@ -25,6 +27,7 @@ androidx-constraintlayout = { group = "androidx.constraintlayout", name = "const
2527

2628
jetbrains-kotlin-compiler-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-compiler-embeddable", version.ref = "kotlin" }
2729

30+
stslex-compilerPlugin = { group = "io.github.stslex", name = "compiler-plugin", version.ref = "stslexCompilerPlugin" }
2831
[plugins]
2932
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
3033
application = { id = "com.android.application", version.ref = "androidGradlePlugin" }

settings.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
pluginManagement {
2+
includeBuild("compiler-plugin")
23
repositories {
34
gradlePluginPortal()
45
google()
56
mavenCentral()
6-
flatDir {
7-
dirs("../compiler-plugin-lib/build/libs")
8-
}
7+
8+
// for getting plugin from local maven repository
9+
// mavenLocal()
910
}
1011
}
1112

@@ -21,5 +22,4 @@ dependencyResolutionManagement {
2122

2223
rootProject.name = "CompilerPlugin"
2324

24-
include(":compiler-plugin")
2525
include(":app")

0 commit comments

Comments
 (0)