@@ -32,36 +32,14 @@ class GitVersionPluginTests extends Specification {
32
32
File buildFile
33
33
File gitIgnoreFile
34
34
File dirtyContentFile
35
-
36
- def setup () {
37
- projectDir = temporaryFolder. root
38
- buildFile = temporaryFolder. newFile(' build.gradle' )
39
- gitIgnoreFile = temporaryFolder. newFile(' .gitignore' )
40
- dirtyContentFile = temporaryFolder. newFile(' dirty' )
41
-
42
- def pluginClasspathResource = getClass(). classLoader. findResource(" plugin-classpath.txt" )
43
- if (pluginClasspathResource == null ) {
44
- throw new IllegalStateException (" Did not find plugin classpath resource, run `testClasses` build task." )
45
- }
46
-
47
- def pluginClasspath = pluginClasspathResource. readLines()
48
- .collect { it. replace(' \\ ' , ' \\\\ ' ) } // escape backslashes in Windows paths
49
- .collect { " '$it '" }
50
- .join(" , " )
51
-
52
- buildFile << """
53
- buildscript {
54
- dependencies {
55
- classpath files($pluginClasspath )
56
- }
57
- }
58
- """ . stripIndent()
59
- }
35
+ List<File > pluginClasspath
60
36
61
37
def ' exception when project root does not have a git repo' () {
62
38
given :
63
39
buildFile << '''
64
- apply plugin: 'com.palantir.git-version'
40
+ plugins {
41
+ id 'com.palantir.git-version'
42
+ }
65
43
version gitVersion()
66
44
''' . stripIndent()
67
45
@@ -75,7 +53,9 @@ class GitVersionPluginTests extends Specification {
75
53
def ' unspecified when no tags are present' () {
76
54
given :
77
55
buildFile << '''
78
- apply plugin: 'com.palantir.git-version'
56
+ plugins {
57
+ id 'com.palantir.git-version'
58
+ }
79
59
version gitVersion()
80
60
''' . stripIndent()
81
61
Git git = Git . init(). setDirectory(projectDir). call();
@@ -90,7 +70,9 @@ class GitVersionPluginTests extends Specification {
90
70
def ' unspecified when no annotated tags are present' () {
91
71
given :
92
72
buildFile << '''
93
- apply plugin: 'com.palantir.git-version'
73
+ plugins {
74
+ id 'com.palantir.git-version'
75
+ }
94
76
version gitVersion()
95
77
''' . stripIndent()
96
78
gitIgnoreFile << ' build'
@@ -108,7 +90,9 @@ class GitVersionPluginTests extends Specification {
108
90
def ' unspecified and dirty when no annotated tags are present and dirty content' () {
109
91
given :
110
92
buildFile << '''
111
- apply plugin: 'com.palantir.git-version'
93
+ plugins {
94
+ id 'com.palantir.git-version'
95
+ }
112
96
version gitVersion()
113
97
''' . stripIndent()
114
98
gitIgnoreFile << ' build'
@@ -127,7 +111,9 @@ class GitVersionPluginTests extends Specification {
127
111
def ' git describe when annotated tag is present' () {
128
112
given :
129
113
buildFile << '''
130
- apply plugin: 'com.palantir.git-version'
114
+ plugins {
115
+ id 'com.palantir.git-version'
116
+ }
131
117
version gitVersion()
132
118
''' . stripIndent()
133
119
gitIgnoreFile << ' build'
@@ -146,7 +132,9 @@ class GitVersionPluginTests extends Specification {
146
132
def ' git describe and dirty when annotated tag is present and dirty content' () {
147
133
given :
148
134
buildFile << '''
149
- apply plugin: 'com.palantir.git-version'
135
+ plugins {
136
+ id 'com.palantir.git-version'
137
+ }
150
138
version gitVersion()
151
139
''' . stripIndent()
152
140
gitIgnoreFile << ' build'
@@ -164,7 +152,26 @@ class GitVersionPluginTests extends Specification {
164
152
}
165
153
166
154
private GradleRunner with (String ... tasks ) {
167
- GradleRunner . create(). withProjectDir(projectDir). withArguments(tasks)
155
+ GradleRunner . create()
156
+ .withPluginClasspath(pluginClasspath)
157
+ .withProjectDir(projectDir)
158
+ .withArguments(tasks)
159
+ }
160
+
161
+ def setup () {
162
+ projectDir = temporaryFolder. root
163
+ buildFile = temporaryFolder. newFile(' build.gradle' )
164
+ gitIgnoreFile = temporaryFolder. newFile(' .gitignore' )
165
+ dirtyContentFile = temporaryFolder. newFile(' dirty' )
166
+
167
+ def pluginClasspathResource = getClass(). classLoader. findResource(" plugin-classpath.txt" )
168
+ if (pluginClasspathResource == null ) {
169
+ throw new IllegalStateException (" Did not find plugin classpath resource, run `testClasses` build task." )
170
+ }
171
+
172
+ pluginClasspath = pluginClasspathResource. readLines()
173
+ .collect { it. replace(' \\ ' , ' \\\\ ' ) } // escape backslashes in Windows paths
174
+ .collect { new File (it) }
168
175
}
169
176
170
177
}
0 commit comments