-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
128 lines (114 loc) · 4.9 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// buildSrc is a trap, use composite builds
// https://docs.gradle.org/current/userguide/structuring_software_products.html
// this is the umbrella build to define cross-build lifecycle tasks.
// https://docs.gradle.org/current/userguide/structuring_software_products_details.html
import java.text.SimpleDateFormat
import java.util.*
plugins {
`java-library`
`maven-publish`
}
// Configures this project and each of its sub-projects.
allprojects {
repositories {
mavenCentral()
// add sonatype snapshots repository
maven {
url=uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
// Managing plugin versions via pluginManagement in settings.gradle.kts
// mavenLocal() // only for testing
}
}
// Configures the sub-projects of this project.
subprojects {
group = "io.github.linguaphylo"
val webSteam = "github.com/LinguaPhylo/LPhyB2"
val web = "https://${webSteam}"
val homepage = web // may be different to github page
var calendar: Calendar? = Calendar.getInstance()
var formatter = SimpleDateFormat("dd-MMM-yyyy HH:mm:ss")
// this task call GenerateMavenPom task to create pom.xml
// and copy it to classes/java/main, so do not need to guess path when module.getResourceAsStream()
val copyPom by tasks.registering(Copy::class) {
dependsOn(tasks.withType(GenerateMavenPom::class))
from(layout.buildDirectory.dir("publications/${project.name}"))
include("**/*.xml")
into(layout.buildDirectory.dir("classes/java/main"))
// into(layout.buildDirectory.dir("resources/main/META-INF/maven/${project.group}/${project.name}"))
rename("pom-default.xml", "pom.xml")
}
// shared attributes
tasks.withType<Jar>() {
// this includes pom.xml in the jar
// dependsOn(copyPom)
manifest {
attributes(
"Implementation-Version" to archiveVersion,
"Implementation-URL" to web,
"Built-By" to "LPhy team", //System.getProperty("user.name"),
"Build-Jdk" to JavaVersion.current().majorVersion.toInt(),
"Built-Date" to formatter.format(calendar?.time)
)
}
// copy LICENSE to META-INF
metaInf {
from(rootDir) {
include("LICENSE")
}
}
}
// configure the shared contents in MavenPublication especially POM
afterEvaluate{
// exclude subproject beast2, publish both in lphybeast
if (!project.name.equals("LPhyB2")) {
extensions.configure<PublishingExtension> {
publications {
withType<MavenPublication>().all() {
// only for name.contains("lphy")
if (name.contains("lphyb2")) {
// Configures the version mapping strategy
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
pom {
name.set(project.name)
// description.set("...")
// compulsory
url.set(homepage)
// packaging = "jar"
properties.set(
mapOf(
"maven.compiler.source" to java.sourceCompatibility.majorVersion,
"maven.compiler.target" to java.targetCompatibility.majorVersion
)
)
licenses {
license {
name.set("GNU Lesser General Public License, version 3")
url.set("https://www.gnu.org/licenses/lgpl-3.0.txt")
}
}
// developers {
// ...
// }
// https://central.sonatype.org/publish/requirements/
scm {
connection.set("scm:git:git://${webSteam}.git")
developerConnection.set("scm:git:ssh://${webSteam}.git")
url.set(web)
}
}
println("Define MavenPublication ${name} and set shared contents in POM")
}
}
}
}
}
}
}