Skip to content
This repository was archived by the owner on Jan 25, 2021. It is now read-only.

Commit 44fe057

Browse files
committed
correctly handle new api and implementation configurations
1 parent ac5a066 commit 44fe057

File tree

3 files changed

+129
-4
lines changed

3 files changed

+129
-4
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ repositories {
1616
}
1717

1818
ext {
19-
androidGradleBuildVersion = '3.0.0-alpha1'
2019
gradleVersions = '4.1'
20+
androidGradleBuildVersion = '3.0.0-beta3'
2121
androidCompileSdkVersion = 'android-26'
22-
androidBuildToolsVersion = '26.0.0'
22+
androidBuildToolsVersion = '26.0.1'
2323
}
2424

2525
configurations {

src/main/java/org/gradle/api/plugins/AndroidMavenPlugin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ private MavenPluginConvention addConventionObject(ProjectInternal project, Maven
195195
}
196196

197197
private void configureAndroidScopeMappings(ConfigurationContainer configurations, Conf2ScopeMappingContainer mavenScopeMappings) {
198+
mavenScopeMappings.addMapping(COMPILE_PRIORITY, configurations.getByName(JavaPlugin.API_CONFIGURATION_NAME),
199+
Conf2ScopeMappingContainer.COMPILE);
198200
mavenScopeMappings.addMapping(COMPILE_PRIORITY, configurations.getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME),
199201
Conf2ScopeMappingContainer.COMPILE);
202+
mavenScopeMappings.addMapping(RUNTIME_PRIORITY, configurations.getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME),
203+
Conf2ScopeMappingContainer.RUNTIME);
204+
mavenScopeMappings.addMapping(TEST_COMPILE_PRIORITY, configurations.getByName(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME),
205+
Conf2ScopeMappingContainer.TEST);
206+
mavenScopeMappings.addMapping(TEST_RUNTIME_PRIORITY, configurations.getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME),
207+
Conf2ScopeMappingContainer.TEST);
200208
}
201209

202210
private void configureJavaScopeMappings(ConfigurationContainer configurations, Conf2ScopeMappingContainer mavenScopeMappings) {

src/test/groovy/org/gradle/api/plugins/AndroidMavenPluginIT.groovy

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,101 @@ class AndroidMavenPluginIT extends Specification {
8686
group = 'org.test'
8787
version = '1.0'
8888
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+
89184
install {
90185
repositories {
91186
// Should be mavenInstaller but cannot find how to override the location
@@ -99,6 +194,13 @@ class AndroidMavenPluginIT extends Specification {
99194
compileSdkVersion "${androidCompileSdkVersion}"
100195
buildToolsVersion "${androidBuildToolsVersion}"
101196
}
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+
}
102204
103205
task runGradleTest {
104206
dependsOn install
@@ -115,13 +217,16 @@ class AndroidMavenPluginIT extends Specification {
115217

116218
then:
117219
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');
119224

120225
where:
121226
gradleVersion << gradleVersions
122227
}
123228

124-
private void validateRepo(String version) {
229+
private File validateRepo(String version) {
125230
File repo = new File(testProjectDir.root, version + "/repo/org/test/simple")
126231
assert repo.exists()
127232

@@ -145,5 +250,17 @@ class AndroidMavenPluginIT extends Specification {
145250
assert pom.exists()
146251
assert pomMd5.exists()
147252
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;
148265
}
149266
}

0 commit comments

Comments
 (0)