forked from atlassian-labs/nadel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
190 lines (167 loc) · 5.95 KB
/
build.gradle
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import java.text.SimpleDateFormat
plugins {
id "org.jetbrains.kotlin.jvm" version "1.6.10"
id "com.jfrog.artifactory" version "4.29.2"
id "biz.aQute.bnd.builder" version "6.3.1"
id "com.bnorm.power.kotlin-power-assert" version "0.11.0"
}
if (JavaVersion.current() != JavaVersion.VERSION_11) {
def msg = String.format("This build must be run with Java 11 - you are running %s - Gradle finds the JDK via JAVA_HOME=%s",
JavaVersion.current(), System.getenv("JAVA_HOME"))
throw new GradleException(msg)
}
def getDevelopmentVersion() {
def output = new StringBuilder()
def error = new StringBuilder()
def gitShortHash = ["git", "-C", projectDir.toString(), "rev-parse", "--short", "HEAD"].execute()
gitShortHash.waitForProcessOutput(output, error)
def gitHash = output.toString().trim()
if (gitHash.isEmpty()) {
println "Git hash is empty: error: ${error.toString()}"
throw new IllegalStateException("Git hash could not be determined")
}
def version = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss").format(new Date()) + "-" + gitHash
println "Created development version: $version"
version
}
def releaseVersion = System.env.RELEASE_VERSION
version = releaseVersion ? releaseVersion : getDevelopmentVersion()
group = "com.atlassian"
allprojects {
description = "Nadel is a Java library that combines multiple GrahpQL services together into one API."
}
gradle.buildFinished { buildResult ->
println "*******************************"
println "*"
if (buildResult.failure != null) {
println "* FAILURE - ${buildResult.failure}"
} else {
println "* SUCCESS"
}
println "* Version: $version"
println "*"
println "*******************************"
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
subprojects {
// Don't publish test
if (project.name == "test") {
return
}
apply plugin: "java"
apply plugin: "java-library"
apply plugin: "signing"
apply plugin: "maven-publish"
apply plugin: "com.jfrog.artifactory"
task sourcesJar(type: Jar) {
dependsOn classes
classifier "sources"
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier "javadoc"
from javadoc.destinationDir
}
publishing {
publications {
nadel(MavenPublication) {
from components.java
artifact sourcesJar {
classifier "sources"
}
artifact javadocJar {
classifier "javadoc"
}
// This used to be in settings.gradle but it seems that Kotlin gets angry when you rename the project name
// It gets angry in the sense that it doesn't think the test/ and main/ src sets are in the same module
// And members with internal modifier in main/ can't be seen in test/
def projectName = project.name == "lib" ? "nadel" : project.name
groupId rootProject.group
artifactId projectName
version rootProject.version
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name projectName
description project.description
url "https://github.com/atlassian-labs/nadel"
scm {
url "https://github.com/atlassian-labs/nadel"
connection "https://github.com/atlassian-labs/nadel"
developerConnection "https://github.com/atlassian-labs/nadel"
}
licenses {
license {
name "Apache License 2.0"
url "https://www.apache.org/licenses/"
distribution "repo"
}
}
developers {
developer {
id "andimarek"
name "Andreas Marek"
}
}
}
}
}
}
}
tasks.withType(PublishToMavenRepository) {
dependsOn(build)
}
signing {
if (System.getenv("SIGNING_KEY") != null) {
useInMemoryPgpKeys(System.getenv("SIGNING_KEY"), System.getenv("SIGNING_PASSWORD"))
sign(publishing.publications)
}
}
javadoc {
options.encoding = "UTF-8"
}
artifacts {
archives sourcesJar
archives javadocJar
}
artifactory {
publish {
setContextUrl("https://packages.atlassian.com/")
repository {
repoKey = "maven-central"
username = System.env.ARTIFACTORY_USERNAME
password = System.env.ARTIFACTORY_API_KEY
}
defaults {
publications("nadel")
publishIvy = false
// This needs to be "false", otherwise, the artifactory plugin will try to publish
// a build info file to Artifactory and fail because we don't have the permissions to do that.
publishBuildInfo = false
}
}
}
}
configurations {
ktlint
}
dependencies {
ktlint "com.pinterest:ktlint:0.39.0"
}
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations"
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "-F", "src/**/*.kt"
}
task ktlintSetCodeStyle(type: JavaExec) {
description = "Apply Kotlin formatter style"
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "applyToIDEAProject", "-y"
}