@@ -86,6 +86,101 @@ class AndroidMavenPluginIT extends Specification {
86
86
group = 'org.test'
87
87
version = '1.0'
88
88
89
+ repositories {
90
+ mavenCentral()
91
+ }
92
+
93
+ install {
94
+ repositories {
95
+ // Should be mavenInstaller but cannot find how to override the location
96
+ mavenDeployer {
97
+ repository(url: "${ uri} /${ gradleVersion} /repo")
98
+ }
99
+ }
100
+ }
101
+
102
+ android {
103
+ compileSdkVersion "${ androidCompileSdkVersion} "
104
+ buildToolsVersion "${ androidBuildToolsVersion} "
105
+ }
106
+
107
+ dependencies {
108
+ compile 'commons-io:commons-io:2.2'
109
+
110
+ testCompile 'junit:junit:4.12'
111
+ }
112
+
113
+ task runGradleTest {
114
+ dependsOn install
115
+ }
116
+ """
117
+
118
+ when :
119
+ def result = GradleRunner . create()
120
+ .withGradleVersion(gradleVersion)
121
+ .withProjectDir(testProjectDir. root)
122
+ .withArguments(' install' )
123
+ .withPluginClasspath()
124
+ .build()
125
+
126
+ then :
127
+ result. task(" :install" ). outcome == SUCCESS
128
+ File pom = validateRepo(gradleVersion);
129
+ validateDependencyScope(pom, ' commons-io' , ' commons-io' , ' 2.2' , ' compile' );
130
+ validateDependencyScope(pom, ' junit' , ' junit' , ' 4.12' , ' test' );
131
+
132
+ where :
133
+ gradleVersion << gradleVersions
134
+ }
135
+
136
+ @Unroll
137
+ def " api and implementation is resolved with gradle #gradleVersion" () {
138
+ given :
139
+ androidManifest << """ <?xml version="1.0" encoding="utf-8"?>
140
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.test.simple" android:versionCode="1" android:versionName="1.0" >
141
+ <application />
142
+ </manifest>
143
+ """
144
+
145
+ settingsFile << " rootProject.name = 'simple'"
146
+
147
+ gradlePropertiesFile << " org.gradle.jvmargs=-javaagent:${ jacocoRuntime} =destfile=${ buildDir} /jacoco/testKit-${ gradleVersion} .exec"
148
+
149
+ def classpathString = pluginClasspath
150
+ .collect { it. absolutePath. replace(' \\ ' , ' /' ) }
151
+ .collect { " '$it '" }
152
+ .join(" , " )
153
+
154
+ def uri = testProjectDir. root. toURI()
155
+ buildFile << """
156
+ buildscript {
157
+ System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
158
+
159
+ repositories {
160
+ jcenter()
161
+ mavenCentral()
162
+ mavenLocal()
163
+ maven {
164
+ url 'https://maven.google.com'
165
+ }
166
+ }
167
+
168
+ dependencies {
169
+ classpath "com.android.tools.build:gradle:${ androidGradleBuildVersion} "
170
+ classpath files(${ classpathString} )
171
+ }
172
+ }
173
+
174
+ apply plugin: 'com.android.library'
175
+ apply plugin: 'com.github.dcendents.android-maven'
176
+
177
+ group = 'org.test'
178
+ version = '1.0'
179
+
180
+ repositories {
181
+ mavenCentral()
182
+ }
183
+
89
184
install {
90
185
repositories {
91
186
// Should be mavenInstaller but cannot find how to override the location
@@ -99,6 +194,13 @@ class AndroidMavenPluginIT extends Specification {
99
194
compileSdkVersion "${ androidCompileSdkVersion} "
100
195
buildToolsVersion "${ androidBuildToolsVersion} "
101
196
}
197
+
198
+ dependencies {
199
+ api 'commons-io:commons-io:2.2'
200
+ implementation 'org.codehaus.groovy:groovy-all:2.4.11'
201
+
202
+ testCompile 'junit:junit:4.12'
203
+ }
102
204
103
205
task runGradleTest {
104
206
dependsOn install
@@ -115,13 +217,16 @@ class AndroidMavenPluginIT extends Specification {
115
217
116
218
then :
117
219
result. task(" :install" ). outcome == SUCCESS
118
- validateRepo(gradleVersion);
220
+ File pom = validateRepo(gradleVersion);
221
+ validateDependencyScope(pom, ' commons-io' , ' commons-io' , ' 2.2' , ' compile' );
222
+ validateDependencyScope(pom, ' org.codehaus.groovy' , ' groovy-all' , ' 2.4.11' , ' runtime' );
223
+ validateDependencyScope(pom, ' junit' , ' junit' , ' 4.12' , ' test' );
119
224
120
225
where :
121
226
gradleVersion << gradleVersions
122
227
}
123
228
124
- private void validateRepo (String version ) {
229
+ private File validateRepo (String version ) {
125
230
File repo = new File (testProjectDir. root, version + " /repo/org/test/simple" )
126
231
assert repo. exists()
127
232
@@ -145,5 +250,17 @@ class AndroidMavenPluginIT extends Specification {
145
250
assert pom. exists()
146
251
assert pomMd5. exists()
147
252
assert pomSha1. exists()
253
+
254
+ // System.out.println(pom.text);
255
+ return pom;
256
+ }
257
+
258
+ private void validateDependencyScope (File pom , String groupId , String artifactId , String version , String scope ) {
259
+ def project = new XmlSlurper (). parse(pom);
260
+ def dependencies = project. dependencies;
261
+ def dependency = dependencies. ' *' . find { node ->
262
+ node. groupId = groupId && node. artifactId == artifactId && node. version == version
263
+ }
264
+ assert dependency. scope == scope;
148
265
}
149
266
}
0 commit comments