/
ScalaPluginIntegrationTest.groovy
264 lines (243 loc) · 8.36 KB
/
ScalaPluginIntegrationTest.groovy
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.scala
import org.gradle.api.plugins.scala.ScalaBasePlugin
import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import org.gradle.integtests.fixtures.ToBeFixedForConfigurationCache
import org.gradle.integtests.fixtures.executer.GradleContextualExecuter
import spock.lang.Issue
import static org.hamcrest.CoreMatchers.containsString
import static org.hamcrest.CoreMatchers.not
class ScalaPluginIntegrationTest extends AbstractIntegrationSpec {
@Issue("https://issues.gradle.org/browse/GRADLE-3094")
def "can apply scala plugin"() {
file("build.gradle") << """
apply plugin: "scala"
task someTask
"""
expect:
succeeds("someTask")
}
@Issue("https://github.com/gradle/gradle/issues/6558")
def "can build in parallel with lazy tasks"() {
settingsFile << """
include 'a', 'b', 'c', 'd'
"""
buildFile << """
allprojects {
tasks.withType(AbstractScalaCompile) {
options.fork = true
}
${mavenCentralRepository()}
plugins.withId("scala") {
dependencies {
implementation("org.scala-lang:scala-library:2.12.6")
}
}
}
"""
['a', 'b', 'c', 'd'].each { project ->
file("${project}/build.gradle") << """
plugins {
id 'scala'
}
"""
file("${project}/src/main/scala/${project}/${project.toUpperCase()}.scala") << """
package ${project}
trait ${project.toUpperCase()}
"""
}
file("a/build.gradle") << """
dependencies {
implementation(project(":b"))
implementation(project(":c"))
implementation(project(":d"))
}
"""
expect:
succeeds(":a:classes", "--parallel")
true
}
@Issue("https://github.com/gradle/gradle/issues/6735")
def "can depend on the source set of another Java project"() {
settingsFile << """
include 'java', 'scala'
"""
buildFile << """
allprojects {
${mavenCentralRepository()}
}
project(":java") {
apply plugin: 'java'
}
project(":scala") {
apply plugin: 'scala'
dependencies {
implementation("org.scala-lang:scala-library:2.12.6")
implementation(project(":java").sourceSets.main.output)
}
}
"""
file("java/src/main/java/Bar.java") << """
public class Bar {}
"""
file("scala/src/test/scala/Foo.scala") << """
trait Foo {
val bar: Bar
}
"""
expect:
succeeds(":scala:testClasses")
}
@Issue("https://github.com/gradle/gradle/issues/6750")
def "can depend on Scala project from other project"() {
settingsFile << """
include 'other', 'scala'
"""
buildFile << """
allprojects {
${mavenCentralRepository()}
}
project(":other") {
apply plugin: 'base'
configurations {
conf
}
dependencies {
conf(project(":scala"))
}
task resolve {
dependsOn configurations.conf
doLast {
println configurations.conf.files
}
}
}
project(":scala") {
apply plugin: 'scala'
dependencies {
implementation("org.scala-lang:scala-library:2.12.6")
}
}
"""
file("scala/src/main/scala/Bar.scala") << """
class Bar {
}
"""
expect:
succeeds(":other:resolve")
}
@Issue("https://github.com/gradle/gradle/issues/7014")
def "can use Scala with war and ear plugins"() {
settingsFile << """
include 'war', 'ear'
"""
buildFile << """
allprojects {
${mavenCentralRepository()}
apply plugin: 'scala'
dependencies {
implementation("org.scala-lang:scala-library:2.12.6")
}
}
project(":war") {
apply plugin: 'war'
}
project(":ear") {
apply plugin: 'ear'
dependencies {
deploy project(path: ':war', configuration: 'archives')
}
}
"""
file("war/src/main/scala/Bar.scala") << """
class Bar {
}
"""
expect:
succeeds(":ear:assemble")
// The Scala incremental compilation mapping should not be exposed to anything else
file("ear/build/tmp/ear/application.xml").assertContents(not(containsString("implementationScala.mapping")))
}
def "forcing an incompatible version of Scala fails with a clear error message"() {
settingsFile << """
rootProject.name = "scala"
"""
buildFile << """
apply plugin: 'scala'
${mavenCentralRepository()}
dependencies {
implementation("org.scala-lang:scala-library")
}
configurations.all {
resolutionStrategy.force "org.scala-lang:scala-library:2.10.7"
}
"""
file("src/main/scala/Foo.scala") << """
class Foo
"""
when:
fails("assemble")
then:
def expectedMessage = "The version of 'scala-library' was changed while using the default Zinc version." +
" Version 2.10.7 is not compatible with org.scala-sbt:zinc_2.12:" + ScalaBasePlugin.DEFAULT_ZINC_VERSION
if (GradleContextualExecuter.isConfigCache()) {
// Nested in the CC problems report
failure.assertHasFailures(2)
failure.assertHasFailure("Configuration cache problems found in this build.") { fail ->
fail.assertHasCause(expectedMessage)
}
} else {
failureHasCause(expectedMessage)
}
}
@ToBeFixedForConfigurationCache(because = ":dependencyInsight")
def "trying to use an old version of Zinc switches to Gradle-supported version"() {
settingsFile << """
rootProject.name = "scala"
"""
buildFile << """
apply plugin: 'scala'
${mavenCentralRepository()}
dependencies {
zinc("com.typesafe.zinc:zinc:0.3.6")
implementation("org.scala-lang:scala-library:2.12.6")
}
"""
file("src/main/scala/Foo.scala") << """
class Foo
"""
expect:
succeeds("assemble")
succeeds("dependencyInsight", "--configuration", "zinc", "--dependency", "zinc")
}
@ToBeFixedForConfigurationCache(because = ":dependencies")
@Issue("gradle/gradle#19300")
def 'show that log4j-core, if present, is 2_17_0 at the minimum'() {
given:
file('build.gradle') << """
apply plugin: 'scala'
${mavenCentralRepository()}
"""
def versionPattern = ~/.*-> 2\.(\d+).*/
expect:
succeeds('dependencies', '--configuration', 'zinc')
def log4jOutput = result.getOutputLineThatContains("log4j-core:{require 2.17.0; reject [2.0, 2.17)}")
def matcher = log4jOutput =~ versionPattern
matcher.find()
Integer.valueOf(matcher.group(1)) >= 16
}
}