kelemen / netbeans-gradle-project

This project is a NetBeans plugin able to open Gradle based Java projects. The implementation is based on Geertjan Wielenga's plugin.
170 stars 57 forks source link

Dagger2 generated code and gradle + netbeans #396

Open fwelland opened 6 years ago

fwelland commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Ok that totally worked!

That for your help!

Your work on G4NB is invaluable!