Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger2 generated code and gradle + netbeans #396

Open
fwelland opened this issue Aug 31, 2018 · 4 comments
Open

Dagger2 generated code and gradle + netbeans #396

fwelland opened this issue Aug 31, 2018 · 4 comments

Comments

@fwelland
Copy link

Env: NB 8.2, JDK 1.8.0.162, Linux x64, Gradle4NB plugin 1.4.3

Not sure if this is an issue with NB or G4NB or maybe just something in my build.gradle, but here it is: doing some work with JavaSE & Dagger2. Dagger2 generates some code, which tucks nicely into build/classes/java/main. With Dagger2 apps, you do code to some of the generated code. I have a very vanilla build.gradle and my simple app builds/runs fine in on the CLI and in NB. HOWEVER, NB will mark the classes using generated code as 'broken' (red error indicator in the projects panel, and such).

Without changing my build.gradle, is there a way to make NB (or G4NB) "see" the generated code so that NB doesn't show not found error symbols?

My build.gradle looks like:

plugins{
    id 'java'
}

repositories {
    jcenter()
}

dependencies {
    implementation 'com.google.dagger:dagger:2.17'    
    annotationProcessor 'com.google.dagger:dagger-compiler:2.17'    
}

wrapper {
    gradleVersion = '4.10'
}

task run(type: JavaExec, dependsOn: 'classes') {
    main = 'fhw.dagger.Main'
    classpath = sourceSets.main.runtimeClasspath
}

Upgrading to NB9/G4NB 2.x not on the radar right now.

@kelemen
Copy link
Owner

kelemen commented Sep 2, 2018

It might be because the annotationProcessor configuration is not read by the plugin. Can you check if this would help:

def processors = ['com.google.dagger:dagger-compiler:2.17']
processors.forEach { it ->
    if (project.hasProperty('evaluatingIDE') && project.property('evaluatingIDE') == 'NetBeans') {
        dependencies.implementation it
    } else {
        dependencies.annotationProcessor it
    }
}

Obviously, replacing your annotationProcessor declarations.

EDIT: Had to switch the configuration names.

@fwelland
Copy link
Author

fwelland commented Oct 2, 2018

Sorry this message slipped thru the cracks.

So I tried your suggestion. No luck really, but I didn't fully understand what I need to do. So I c-n-p the above code into my build.gradle and that just got me to:
> Could not find method annotationProcessor() for arguments [com.google.dagger:dagger-compiler:2.17]

I didn't quite understand what you mean about replacing your annotationProcessor declarations. I changed my deps to be a more "normal":

compile 'com.google.dagger:dagger:2.17' runtime 'com.google.dagger:dagger-compiler:2.17'

and then:
compile 'com.google.dagger:dagger:2.17' compile 'com.google.dagger:dagger-compiler:2.17'
And then just omitting dagger-compiler:2.17 altogether.

Still same error about missing annotationProcessor() method.

Maybe I miss understood something.

@kelemen
Copy link
Owner

kelemen commented Oct 2, 2018

I have updated the previous code snippet (I missed the dependencies part, I guess that is what I get for not trying out the code).

@fwelland
Copy link
Author

fwelland commented Oct 3, 2018

Ok that totally worked!

That for your help!

Your work on G4NB is invaluable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants