Skip to content

Commit

Permalink
Add Gradle test that repros issues in #3090.
Browse files Browse the repository at this point in the history
This CL adds a repro test for the issues in #3090 when a transitive annotation is no longer on the classpath.

Follow-up CLs will fix the remaining issues.

RELNOTES=N/A
PiperOrigin-RevId: 419677447
  • Loading branch information
bcorso authored and Dagger Team committed Jan 4, 2022
1 parent 36c17bb commit 605e88c
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 0 deletions.
3 changes: 3 additions & 0 deletions javatests/artifacts/dagger/settings.gradle
Expand Up @@ -3,3 +3,6 @@ include ':build-tests'
include ':java-app'
include ':kotlin-app'
include ':kotlin-app:kotlin-library'
include ':transitive-annotation-app'
include ':transitive-annotation-app:library1'
include ':transitive-annotation-app:library2'
31 changes: 31 additions & 0 deletions javatests/artifacts/dagger/transitive-annotation-app/build.gradle
@@ -0,0 +1,31 @@
/*
* 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 'java'
id 'application'
}

java {
// Make sure the generated source is compatible with Java 7.
sourceCompatibility = JavaVersion.VERSION_1_7
}

dependencies {
implementation project(":transitive-annotation-app:library1")
implementation "com.google.dagger:dagger:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
}
@@ -0,0 +1,31 @@
/*
* 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 'java'
id 'java-library'
}

java {
// Make sure the generated source is compatible with Java 7.
sourceCompatibility = JavaVersion.VERSION_1_7
}

dependencies {
implementation project(":transitive-annotation-app:library2")
implementation "com.google.dagger:dagger:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
}
@@ -0,0 +1,62 @@
/*
* 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 library1;

import static library2.MyTransitiveAnnotation.VALUE;

import javax.inject.Inject;
import javax.inject.Singleton;
import library2.MyTransitiveAnnotation;

/**
* A class used to test that Dagger won't fail when non-dagger related annotations cannot be
* resolved.
*
* <p>During the compilation of {@code :app}, {@link MyTransitiveAnnotation} will no longer be on
* the classpath. In most cases, Dagger shouldn't care that the annotation isn't on the classpath
*/
@Singleton
// @MyTransitiveAnnotation(VALUE): Not supported on inject-types yet.
public final class Foo extends FooBase {
@MyTransitiveAnnotation(VALUE)
int nonDaggerField;

// @MyTransitiveAnnotation(VALUE): Not supported on inject-fields yet.
@Inject int daggerField;

@MyTransitiveAnnotation(VALUE)
Foo(@MyTransitiveAnnotation(VALUE) String str) {
super(str);
}

// @MyTransitiveAnnotation(VALUE): Not supported on inject-constructors yet.
@Inject
Foo(
// @MyTransitiveAnnotation(VALUE): Not supported on inject-constructor parameters yet.
int i) {
super(i);
}

@MyTransitiveAnnotation(VALUE)
void nonDaggerMethod(@MyTransitiveAnnotation(VALUE) int i) {}

// @MyTransitiveAnnotation(VALUE): Not supported on inject-method yet.
@Inject
void daggerMethod(
// @MyTransitiveAnnotation(VALUE): Not supported on inject-method parameters yet.
int i) {}
}
@@ -0,0 +1,50 @@
/*
* 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 library1;

import static library2.MyTransitiveAnnotation.VALUE;

import javax.inject.Inject;
import library2.MyTransitiveAnnotation;

/** A baseclass for {@link Foo}. */
// @MyTransitiveAnnotation(VALUE): Not supported on base-types yet.
public class FooBase {
@MyTransitiveAnnotation(VALUE)
int baseNonDaggerField;

// @MyTransitiveAnnotation(VALUE): Not supported on inject-method parameters yet.
@Inject int baseDaggerField;

@MyTransitiveAnnotation(VALUE)
FooBase(@MyTransitiveAnnotation(VALUE) String str) {}

// @MyTransitiveAnnotation(VALUE): Not supported on inject-constructors yet.
@Inject
FooBase(
// @MyTransitiveAnnotation(VALUE): Not supported on inject-constructor parameters yet.
int i) {}

@MyTransitiveAnnotation(VALUE)
void baseNonDaggerMethod(@MyTransitiveAnnotation(VALUE) int i) {}

// @MyTransitiveAnnotation(VALUE): Not supported on inject-method yet.
@Inject
void baseDaggerMethod(
// @MyTransitiveAnnotation(VALUE): Not supported on inject-method parameters yet.
int i) {}
}
@@ -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.
*/

plugins {
id 'java'
id 'java-library'
}

java {
// Make sure the generated source is compatible with Java 7.
sourceCompatibility = JavaVersion.VERSION_1_7
}
@@ -0,0 +1,24 @@
/*
* 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 library2;

/** An annotation that is a transitive dependency of the app. */
public @interface MyTransitiveAnnotation {
int value();

public static int VALUE = 0;
}
@@ -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 app;

import dagger.BindsInstance;
import dagger.Component;
import javax.inject.Singleton;
import library1.Foo;

@Singleton
@Component
interface MyComponent {
Foo foo();

@Component.Factory
interface Factory {
MyComponent create(@BindsInstance int i);
}
}

0 comments on commit 605e88c

Please sign in to comment.