Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Unable to be compatible with high version of gradle ! #726

Closed
EspoirX opened this issue May 30, 2019 · 9 comments
Closed

Unable to be compatible with high version of gradle ! #726

EspoirX opened this issue May 30, 2019 · 9 comments

Comments

@EspoirX
Copy link

EspoirX commented May 30, 2019

distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip
classpath 'com.android.tools.build:gradle:3.4.1'

Such a configuration cannot generate a file in build/generated/source/apt/debug

@Egorand
Copy link
Collaborator

Egorand commented May 30, 2019

It'd be helpful to have a sample project that reproduces the issue. My feeling is that JavaPoet isn't the culprit here.

@EspoirX
Copy link
Author

EspoirX commented May 31, 2019

You can create a simple APT example to reproduce,like this:

    @AutoService(Processor.class)
    public class MyProcessor extends AbstractProcessor {
        
        private Filer mFiler;
     
        @Override
        public synchronized void init(ProcessingEnvironment processingEnvironment) {
            super.init(processingEnvironment);
            mFiler = processingEnv.getFiler();
        }

        @Override
        public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
            TypeSpec finderClass = TypeSpec.classBuilder("MyTestClass")
                    .addModifiers(Modifier.PUBLIC)
                    .build();
            JavaFile javaFile = JavaFile.builder("com.example.demo", finderClass).build();
            try {
                javaFile.writeTo(mFiler);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return true;
        }

        @Override
        public Set<String> getSupportedAnnotationTypes() {
            Set<String> types = new LinkedHashSet<>();
            types.add(Override.class.getCanonicalName());
            return types;
        }
    }

as you said,I am not sure the problem is in JavaPoet or google#auto-service,But after I lowered the gradle version, the problem was solved. So I hope that you can follow up to make sure it is not a JavaPoet issue.

@tbroyer
Copy link
Collaborator

tbroyer commented May 31, 2019

How are your dependencies configured? And which older version of Gradle is working?
In 5.0 for example, Gradle stopped using processors from the compile classpath, you have to declare your processor dependencies in the annotationProcessor configuration.

@EspoirX
Copy link
Author

EspoirX commented May 31, 2019

yes,My configuration is correct,like this,
annotationProcessor project(':compiler')

@JakeWharton
Copy link
Collaborator

Please provide a full sample project in the form of a zip or GitHub repo that reproduces the problem.

@EspoirX
Copy link
Author

EspoirX commented Jun 3, 2019

demo : https://github.com/EspoirX/IssuesDemo

thanks!

@tbroyer
Copy link
Collaborator

tbroyer commented Jun 3, 2019

Your AutoService dependency should be in both api (or compileOnly as the annotation has source retention) and annotationProcessor.
I haven't tried the project but that alone would break it with Gradle 5.0, as explained earlier.

@WangPney
Copy link

WangPney commented Jul 8, 2019

I have the same problem

@WangPney
Copy link

WangPney commented Jul 8, 2019

My gradle build is gradle-5.1.1-all.zip
Gradle version is 3.4.1
The problem I encountered was also a class generation failure. Do I have to downgrade to use it @ @tbroyer

@EspoirX
Copy link
Author

EspoirX commented Jul 9, 2019

you should downgrade to use it @lichangxing

@Shadowself
Copy link

So Have you solved it?

@EspoirX EspoirX closed this as completed Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants