Skip to content

Commit 5a8196f

Browse files
committed
Add test
1 parent 4f914a8 commit 5a8196f

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package org.gradlex.javamodule.dependencies.test
2+
3+
import org.gradlex.javamodule.dependencies.test.fixture.GradleBuild
4+
import spock.lang.Specification
5+
6+
import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE
7+
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
8+
9+
class SettingsPluginTest extends Specification {
10+
11+
@Delegate
12+
GradleBuild build = new GradleBuild()
13+
14+
def setup() {
15+
settingsFile.text = '''
16+
plugins { id("org.gradlex.java-module-dependencies") }
17+
'''
18+
appBuildFile.delete()
19+
libBuildFile.delete()
20+
}
21+
22+
def "can define individual modules"() {
23+
given:
24+
settingsFile << '''
25+
javaModules {
26+
module("app") { plugin("application") }
27+
module("lib") { plugin("java-library") }
28+
}
29+
'''
30+
libModuleInfoFile << 'module abc.lib { }'
31+
appModuleInfoFile << '''
32+
module org.gradlex.test.app {
33+
requires abc.lib;
34+
}
35+
'''
36+
37+
when:
38+
def result = runner(':app:compileJava').build()
39+
40+
then:
41+
result.task(":app:compileJava").outcome == SUCCESS
42+
result.task(":lib:compileJava").outcome == SUCCESS
43+
}
44+
45+
def "finds all modules in a directory"() {
46+
given:
47+
settingsFile << '''
48+
javaModules {
49+
directory(".") { plugin("java-library") }
50+
}
51+
'''
52+
libModuleInfoFile << 'module abc.lib { }'
53+
appModuleInfoFile << '''
54+
module org.gradlex.test.app {
55+
requires abc.lib;
56+
}
57+
'''
58+
59+
when:
60+
def result = runner(':app:build').build()
61+
62+
then:
63+
result.task(":app:compileJava").outcome == SUCCESS
64+
result.task(":lib:compileJava").outcome == SUCCESS
65+
}
66+
67+
def "automatically sets module for application plugin"() {
68+
given:
69+
settingsFile << '''
70+
javaModules {
71+
directory(".") {
72+
plugin("java-library")
73+
module("app") { plugin("application") }
74+
}
75+
}
76+
'''
77+
libModuleInfoFile << 'module abc.libxyz { }'
78+
appModuleInfoFile << '''
79+
module org.gradlex.test.app {
80+
requires abc.libxyz;
81+
}
82+
'''
83+
appBuildFile << 'application.mainClass = "app.App"'
84+
file("app/src/main/java/app/App.java") << 'package app; public class App { public static void main(String[] args) { } }'
85+
86+
when:
87+
def result = runner(':app:run').build()
88+
89+
then:
90+
result.task(":app:run").outcome == SUCCESS
91+
result.task(":app:compileJava").outcome == SUCCESS
92+
result.task(":lib:compileJava").outcome == SUCCESS
93+
}
94+
95+
def "can depend on test fixtures module"() {
96+
given:
97+
settingsFile << '''
98+
javaModules {
99+
directory(".") {
100+
group = "bar.foo"
101+
plugin("java-library")
102+
plugin("java-test-fixtures")
103+
}
104+
}
105+
'''
106+
libModuleInfoFile << 'module foo.bar.m { }'
107+
file('lib/src/testFixtures/java/module-info.java') << 'module abc.libxyz.dsdsds { }'
108+
appModuleInfoFile << '''
109+
module org.gradlex.test.app {
110+
requires foo.bar.m;
111+
requires abc.libxyz.dsdsds;
112+
}
113+
'''
114+
115+
when:
116+
def result = runner(':app:compileJava').build()
117+
118+
then:
119+
result.task(":app:compileJava").outcome == SUCCESS
120+
result.task(":lib:compileJava").outcome == SUCCESS
121+
result.task(":lib:compileTestFixturesJava").outcome == SUCCESS
122+
}
123+
124+
def 'can apply root project plugin from settings'() {
125+
settingsFile << '''
126+
rootPlugins {
127+
id("java")
128+
}
129+
'''
130+
131+
when:
132+
def result = runner(':compileJava').build()
133+
134+
then:
135+
result.task(":compileJava").outcome == NO_SOURCE
136+
}
137+
138+
}

0 commit comments

Comments
 (0)