forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect ProductFlavorAttr key in Hilt's compileOnly configurati…
…on for the AggregatingTask. RELNOTES=n/a PiperOrigin-RevId: 377447733
- Loading branch information
1 parent
c1359a2
commit d568957
Showing
11 changed files
with
309 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
java/dagger/hilt/android/plugin/src/test/data/flavored-project/app/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger 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. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.application' | ||
id 'dagger.hilt.android.plugin' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.2" | ||
|
||
flavorDimensions 'api', 'version' | ||
productFlavors { | ||
demo { | ||
dimension 'version' | ||
} | ||
full { | ||
dimension 'version' | ||
} | ||
minApi24 { | ||
dimension 'api' | ||
minSdkVersion '24' | ||
versionNameSuffix "-minApi24" | ||
} | ||
minApi21 { | ||
dimension "api" | ||
minSdkVersion '21' | ||
versionNameSuffix "-minApi21" | ||
} | ||
} | ||
|
||
defaultConfig { | ||
applicationId "simple.app" | ||
minSdkVersion 21 | ||
targetSdkVersion 30 | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT' | ||
annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT' | ||
implementation project(':feature') | ||
} | ||
|
||
hilt { | ||
enableAggregatingTask = true | ||
} |
20 changes: 20 additions & 0 deletions
20
...agger/hilt/android/plugin/src/test/data/flavored-project/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- | ||
~ Copyright (C) 2021 The Dagger 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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="simple.app"> | ||
<application android:name=".SimpleApp" android:label="Flavored App"> | ||
</application> | ||
</manifest> |
25 changes: 25 additions & 0 deletions
25
...android/plugin/src/test/data/flavored-project/app/src/main/java/simple/app/SimpleApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger 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 simple.app; | ||
|
||
import android.app.Application; | ||
import dagger.hilt.android.HiltAndroidApp; | ||
|
||
/** Just an application. */ | ||
@HiltAndroidApp | ||
public class SimpleApp extends Application { | ||
} |
30 changes: 30 additions & 0 deletions
30
java/dagger/hilt/android/plugin/src/test/data/flavored-project/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger 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. | ||
*/ | ||
|
||
buildscript { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
mavenLocal() | ||
google() | ||
jcenter() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
java/dagger/hilt/android/plugin/src/test/data/flavored-project/feature/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger 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. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.library' | ||
id 'dagger.hilt.android.plugin' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.2" | ||
|
||
flavorDimensions 'api', 'version' | ||
productFlavors { | ||
demo { | ||
dimension 'version' | ||
} | ||
full { | ||
dimension 'version' | ||
} | ||
minApi24 { | ||
dimension 'api' | ||
minSdkVersion '24' | ||
versionNameSuffix "-minApi24" | ||
} | ||
minApi21 { | ||
dimension "api" | ||
minSdkVersion '21' | ||
versionNameSuffix "-minApi21" | ||
} | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT' | ||
annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT' | ||
} |
18 changes: 18 additions & 0 deletions
18
...r/hilt/android/plugin/src/test/data/flavored-project/feature/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
~ Copyright (C) 2021 The Dagger 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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="simple.library"> | ||
</manifest> |
21 changes: 21 additions & 0 deletions
21
...ugin/src/test/data/flavored-project/feature/src/main/java/simple/library/LibraryCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger 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 simple.library; | ||
|
||
/** Just some 'Library' code */ | ||
public class LibraryCode { | ||
} |
1 change: 1 addition & 0 deletions
1
java/dagger/hilt/android/plugin/src/test/data/flavored-project/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
android.useAndroidX=true |
3 changes: 3 additions & 0 deletions
3
java/dagger/hilt/android/plugin/src/test/data/flavored-project/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rootProject.name='Flavored Project' | ||
include ':app' | ||
include ':feature' |
63 changes: 63 additions & 0 deletions
63
java/dagger/hilt/android/plugin/src/test/kotlin/VariantsConfigurationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger 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. | ||
*/ | ||
|
||
import com.google.common.truth.Expect | ||
import java.io.File | ||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
// Verifies the aggregated task is configured correctly in a multi-module flavored project. | ||
class VariantsConfigurationTest { | ||
@get:Rule | ||
val testProjectDir = TemporaryFolder() | ||
|
||
@get:Rule | ||
val expect: Expect = Expect.create() | ||
|
||
@Before | ||
fun setup() { | ||
val projectRoot = testProjectDir.root | ||
File("src/test/data/flavored-project").copyRecursively(projectRoot) | ||
} | ||
|
||
@Test | ||
fun verifyFlavorConfiguration_demoDebug() { | ||
val result = runGradleTasks(":app:assembleMinApi21DemoDebug") | ||
expect.that(result.task(":app:assembleMinApi21DemoDebug")!!.outcome) | ||
.isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
|
||
@Test | ||
fun verifyFlavorConfiguration_fullRelease() { | ||
val result = runGradleTasks(":app:assembleMinApi24FullRelease") | ||
expect.that(result.task(":app:assembleMinApi24FullRelease")!!.outcome) | ||
.isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
|
||
private fun runGradleTasks(vararg args: String): BuildResult { | ||
return GradleRunner.create() | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments(*args) | ||
.withPluginClasspath() | ||
.forwardOutput() | ||
.build() | ||
} | ||
} |