-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
204 lines (171 loc) · 6.54 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
plugins {
id 'java'
id 'scala'
id 'maven-publish'
id 'signing'
id "com.diffplug.gradle.spotless" version "${spotlessPluginVersion}"
id "com.github.maiflai.scalatest" version "${scalaTestPluginVersion}"
}
ext {
projectVersion = "1.0.0-SNAPSHOT"
scalaMinorVersion = computeScalaMinorVersion(scalaVersion)
pegdown = "1.4.2"
scalaTest = "3.0.9"
macroParadise = "2.1.1"
}
static def computeScalaMinorVersion(String scalaVersion) {
String[] r = scalaVersion.split("\\.");
return r.dropRight(1).join(".")
}
configurations {
scalaCompilerPlugin
}
group 'com.cmhteixeira'
version "${projectVersion}"
sourceCompatibility = 1.8
buildDir = "build${computeScalaMinorVersion(scalaVersion).replace(".", "")}"
// Gradle adds this task which generates extra files on the publication.
// We are not interested in this.
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
// Creates a jar with the output of the 'scalaDoc' task
task scaladocJar(type: Jar, dependsOn: scaladoc) {
archiveClassifier = 'javadoc'
from scaladoc.destinationDir
}
// Creates a jar with the source code
task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
jar {
archivesBaseName = "${project.name}_${computeScalaMinorVersion(scalaVersion)}"
}
publishing {
publications {
myStandardPublication(MavenPublication) {
from components.java
artifact scaladocJar // Publication should include the scala docs
artifact sourcesJar // Publication should include the source code.
groupId = "${project.group}"
artifactId = "${project.name}_${computeScalaMinorVersion("$scalaVersion")}"
version = "${projectVersion}"
pom {
name = "delegate-macro"
description = "Annotation to automatically delegate/proxy implementation of interface to dependency"
url = "https://github.com/cmhteixeira/delegate-macro"
scm {
connection = "git@github.com:cmhteixeira/delegate-macro.git"
url = "https://github.com/cmhteixeira/delegate-macro"
}
licenses {
license {
name = "MIT License"
url = "http://www.opensource.org/licenses/mit-license.php"
}
}
developers {
developer {
id = "cmhteixeira"
name = "Carlos Teixeira"
email = "c.mh.teixeira@gmail.com"
url = "https://github.com/cmhteixeira"
}
}
}
}
}
repositories {
maven {
name = "MavenCentral"
if (projectVersion.endsWith("SNAPSHOT")) {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
} else {
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
}
credentials {
username = System.getenv("ossrhUsername")
password = System.getenv("ossrhPassword")
}
}
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/cmhteixeira/delegate-macro")
credentials {
username = System.getenv("GITHUB_USERNAME")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
signing {
def signingKey = System.getenv("signingKey")
def signingPassword = System.getenv("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.myStandardPublication
}
// We only want to sign artifacts if it is a release
tasks.withType(Sign) {
onlyIf { !projectVersion.endsWith("SNAPSHOT") }
}
tasks.create(name: "printScalaVersion") {
description = "Prints to the console the scala version being used."
doLast {
println("Scala version is: ${scalaVersion}")
}
}
for (coreTask in ["compileScala", "compileTestScala", "build", "test", "publish"]) {
def allScalaVersions = ["2.11.12", "2.12.13", "2.13.5"]
for (sv in allScalaVersions) {
def minorVersion = computeScalaMinorVersion("$sv").replace(".", "")
tasks.create(name: "${coreTask}${minorVersion}", type: GradleBuild) {
description = "Runs the '${coreTask}' task with the scala version set to $sv (Minor version: ${computeScalaMinorVersion("$sv")})"
buildFile = './build.gradle'
startParameter.projectProperties = [scalaVersion: "${sv}"]
tasks = ["printScalaVersion", "${coreTask}".toString()]
}
}
def taskAcrossVersions = allScalaVersions.collect { sv -> "${coreTask}${computeScalaMinorVersion(sv).replace(".", "")}".toString() }
tasks.create(name: "${coreTask}All", dependsOn: taskAcrossVersions) {
description = "Runs tasks ${taskAcrossVersions.join(", ")}".toString()
}
}
repositories {
mavenCentral()
}
spotless {
scala {
scalafmt("2.3.2").configFile(".scalafmt.conf")
}
}
dependencies {
compile("org.scala-lang:scala-library:$scalaVersion")
if (computeScalaMinorVersion(scalaVersion) < "2.13") {
// On version 2.13, the functionality became directly supported by the compiler under flag '-Ymacro-annotations'
scalaCompilerPlugin "org.scalamacros:paradise_$scalaVersion:$macroParadise"
}
compile("org.scala-lang:scala-compiler:$scalaVersion")
compile("org.scala-lang:scala-reflect:$scalaVersion")
testCompile("org.scalatest:scalatest_$scalaMinorVersion:$scalaTest")
testRuntime("org.pegdown:pegdown:$pegdown")
}
tasks.withType(ScalaCompile) {
// Map plugin jars to -Xplugin parameter
List<String> parameters =
configurations.scalaCompilerPlugin.files.collect {
'-Xplugin:' + it.absolutePath
}
// Add existing parameters
List<String> existingParameters = scalaCompileOptions.additionalParameters
if (existingParameters && computeScalaMinorVersion(scalaVersion) == "2.13") { // todo: Does this case make sense?
parameters.addAll(existingParameters)
parameters.add("-Ymacro-annotations")
} else if (existingParameters) {
parameters.addAll(existingParameters)
} else if (computeScalaMinorVersion(scalaVersion) == "2.13") {
parameters.add("-Ymacro-annotations")
}
// Finally set the additionalParameters
scalaCompileOptions.additionalParameters = parameters
}