Skip to content

Commit

Permalink
Request 'processed-jar' in the Hilt Gradle plugin during classpath ag…
Browse files Browse the repository at this point in the history
…gregation so that kotlinc invocations use the processed jar in the '-friend-path' such that internal members are accessible.

Fixes: #2306
RELNOTES=Fix an issue where internal Kotlin classes where not accessible with `enableExperimentalClasspathAggregation` turned ON.
PiperOrigin-RevId: 354151797
  • Loading branch information
danysantiago authored and Dagger Team committed Jan 27, 2021
1 parent 7b6e4bb commit 98c73c6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class HiltGradlePlugin : Plugin<Project> {
// Java/Kotlin library projects offer an artifact of type 'jar'.
spec.from.attribute(ARTIFACT_TYPE_ATTRIBUTE, "jar")
// Android library projects (with or without Kotlin) offer an artifact of type
// 'android-classes', which AGP can offer as a jar.
spec.from.attribute(ARTIFACT_TYPE_ATTRIBUTE, "android-classes-jar")
// 'processed-jar', which AGP can offer as a jar.
spec.from.attribute(ARTIFACT_TYPE_ATTRIBUTE, "processed-jar")
spec.to.attribute(ARTIFACT_TYPE_ATTRIBUTE, DAGGER_ARTIFACT_TYPE_VALUE)
}
}
Expand Down
13 changes: 13 additions & 0 deletions javatests/artifacts/hilt-android/simpleKotlin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ android {
lintOptions {
checkReleaseBuilds = false
}
sourceSets {
String sharedTestDir = 'src/sharedTest/java'
test {
java.srcDirs += sharedTestDir
}
androidTest {
java.srcDirs += sharedTestDir
}
}
}

hilt {
Expand All @@ -58,13 +67,17 @@ hilt {
}

dependencies {
implementation project(':android-library')
implementation project(':kotlin-library')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.activity:activity-ktx:1.1.0'

implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'
kapt 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'

testImplementation 'androidx.test.ext:junit:1.1.2'
testImplementation 'androidx.test:runner:1.3.0'
testImplementation 'com.google.truth:truth:1.0.1'
testImplementation 'junit:junit:4.13'
testImplementation 'org.robolectric:robolectric:4.5-alpha-3'
Expand Down
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 dagger.hilt.android.simpleKotlin

object DefinedStrings {
internal val morningSweet = "Mallorca"
internal fun getInternalSweet() = "Sugar Donuts"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 dagger.hilt.android.simpleKotlin

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

/**
* Verifies internal Kotlin classes are accessible with classpath aggregation.
*/
@RunWith(AndroidJUnit4::class)
class InternalAccessTest {
@Test
fun verifyInternalMembersAreAccessible() {
assertThat(DefinedStrings.morningSweet).isNotNull()
assertThat(DefinedStrings.getInternalSweet()).isNotNull()
}
}

0 comments on commit 98c73c6

Please sign in to comment.