1+ import java.security.MessageDigest
2+
13plugins {
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+
613java {
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+ }
0 commit comments