@@ -3,13 +3,15 @@ import java.util.*
33
44plugins {
55 id(" java" )
6+ id(" maven-publish" )
67}
78
89group = " com.github.luiox"
9- version = " 1.8 "
10+ version = " 1.9 "
1011
1112subprojects {
1213 apply (plugin = " java" )
14+ apply (plugin = " maven-publish" )
1315
1416 // 设置子项目的属性
1517 group = rootProject.group
@@ -19,11 +21,48 @@ subprojects {
1921 dependencies {
2022 testImplementation(platform(" org.junit:junit-bom:${properties[" junit_version" ] as String } " ))
2123 testImplementation(" org.junit.jupiter:junit-jupiter" )
24+
25+ implementation(" org.ow2.asm:asm:${properties[" asm_version" ] as String } " )
26+ implementation(" org.ow2.asm:asm-tree:${properties[" asm_version" ] as String } " )
27+ implementation(" org.ow2.asm:asm-commons:${properties[" asm_version" ] as String } " )
28+ implementation(" org.ow2.asm:asm-analysis:${properties[" asm_version" ] as String } " )
29+ implementation(" org.ow2.asm:asm-util:${properties[" asm_version" ] as String } " )
30+
31+ implementation(" ch.qos.logback:logback-classic:${properties[" logback_version" ] as String } " )
32+ implementation(" ch.qos.logback:logback-core:${properties[" logback_version" ] as String } " )
33+
34+ implementation(" org.jetbrains:annotations:${properties[" jetbrains_annotations_version" ] as String } " )
2235 }
2336
2437 tasks.withType<Test > {
2538 useJUnitPlatform()
2639 }
40+
41+ publishing {
42+ publications {
43+ create<MavenPublication >(" mavenJava" ) {
44+ artifactId = project.name
45+ groupId = project.group.toString()
46+ version = project.version.toString()
47+
48+ from(components[" java" ])
49+
50+ pom.withXml {
51+ val dependenciesNode = asNode().appendNode(" dependencies" )
52+
53+ // 遍历项目依赖并添加到 POM
54+ project.configurations.implementation.get().allDependencies.forEach { dep ->
55+ if (dep.group != null ) { // 过滤掉没有 group 的依赖(如本地项目)
56+ val dependencyNode = dependenciesNode.appendNode(" dependency" )
57+ dependencyNode.appendNode(" groupId" , dep.group)
58+ dependencyNode.appendNode(" artifactId" , dep.name)
59+ dependencyNode.appendNode(" version" , dep.version ? : " " )
60+ }
61+ }
62+ }
63+ }
64+ }
65+ }
2766}
2867
2968allprojects {
0 commit comments