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

Plugin not compiling java code after migration from 0.8.19 -> 0.9.0 #747

Open
cirvladimir opened this issue Feb 26, 2024 · 8 comments
Open

Comments

@cirvladimir
Copy link

cirvladimir commented Feb 26, 2024

Hello, I have an android project I'm trying to migrate. I updated the version of protobuf-gradle-plugin from 0.8.19 to 0.9.0 and now nothing is being generated by the plugin. I've tried several things but couldn't figure out what I'm doing wrong. I can confirm everything works with 0.8.19 but not with 0.9.0.

I'm not seeing any errors, just no generated folder in the build output and a jar file that only contains the input proto file.

Here's my build.gradle file for the project:

apply plugin: 'kotlin'
apply plugin: 'com.google.protobuf'

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.14.0"
    }

    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option "lite"
                }
            }
        }
    }
}

sourceSets {
    main {
        java {
            srcDirs += file("${protobuf.generatedFilesBaseDir}/main/javalite")
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "com.google.protobuf:protobuf-javalite:3.14.0"
}

This is my folder structure:

│   build.gradle
│
│
└───src
                         └───main
                                                    └───proto
                                                                     game.proto
@dl6lr
Copy link

dl6lr commented Mar 8, 2024

I have the same issue with a plain java project. 0.8.19 generates code, but 0.9.4 doesn't. I haven't spotted the difference yet. 0.8.19 throws a lot of deprecation warnings in gradle 8.x and gradle fails to build sourcesJar, so I was trying to update the plugin.

@ejona86
Copy link
Collaborator

ejona86 commented Mar 11, 2024

You say you tried 0.9.0. Did you not try 0.9.4? It was released 9 months ago.

It works fine for me if I remove this:

// DELETE THIS
sourceSets {
    main {
        java {
            srcDirs += file("${protobuf.generatedFilesBaseDir}/main/javalite")
        }
    }
}

That modifies the sourceSet without any dependency information, so that probably only happened to work before. The plugin adds the generated sources to the Java sourceset, so that shouldn't have been needed even with 0.8.x.

@dl6lr
Copy link

dl6lr commented Mar 11, 2024

In my case, the gradle file looks like this (excerpt from a multiproject build):

plugins {
    id 'java-project-plugin'
    id 'com.google.protobuf' version '0.9.4'
}

ext {
    protoGenDir = "${project.buildDir}/src/proto"
}


sourceSets {
    main {
        proto {
            // The folder with the proto files
            srcDir "${project.projectDir}/src/main/resources/proto"
        }
        // seems this is only needed for Eclipse to recognize those generated source folders
        java {
            srcDir "${project.ext.protoGenDir}/main/grpc"
            srcDir "${project.ext.protoGenDir}/main/java"
        }
        // end of eclipse source folder stuff
    }
}

dependencies {
    implementation group: 'io.grpc', name: 'grpc-netty-shaded', version: '1.57.1'
    implementation group: 'io.grpc', name: 'grpc-protobuf', version: '1.57.1'
    implementation group: 'io.grpc', name: 'grpc-stub', version: '1.57.1'
    testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9'
    testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.9'
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.23.4'
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.57.1'
        }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {}
        }
    }
    generatedFilesBaseDir = project.ext.protoGenDir
}

With 0.9.4 and gradle 8.6 it generates nothing, the build folders stay empty, even the extracted-include-protos dir is empty, and the java compile fails because no generated sources. Only build/resources/main/proto is filled with the copied proto files. And the tasks are "UP-TO-DATE" or have "NO-SOURCE"

> Task :terminalmgmtinterface:extractGenProto UP-TO-DATE
Caching disabled for task ':terminalmgmtinterface:extractGenProto' because:
  Build cache is disabled
Skipping task ':terminalmgmtinterface:extractGenProto' as it is up-to-date.
Resolve mutations for :terminalmgmtinterface:extractIncludeGenProto (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:extractIncludeGenProto (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:extractIncludeGenProto UP-TO-DATE
Caching disabled for task ':terminalmgmtinterface:extractIncludeGenProto' because:
  Build cache is disabled
Skipping task ':terminalmgmtinterface:extractIncludeGenProto' as it is up-to-date.
Resolve mutations for :terminalmgmtinterface:generateGenProto (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:generateGenProto (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:generateGenProto NO-SOURCE
Deleting stale output file: D:\projects\Gitrepos\server\terminalmgmtinterface\build\generated\source\proto\gen
Skipping task ':terminalmgmtinterface:generateGenProto' as it has no source files and no previous output files.
Resolve mutations for :terminalmgmtinterface:generateSources (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:generateSources (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:generateSources SKIPPED
Skipping task ':terminalmgmtinterface:generateSources' as task onlyIf 'Task is enabled' is false.
Resolve mutations for :terminalmgmtinterface:compileGenJava (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:compileGenJava (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:compileGenJava NO-SOURCE
Skipping task ':terminalmgmtinterface:compileGenJava' as it has no source files and no previous output files.
Resolve mutations for :terminalmgmtinterface:processGenResources (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:processGenResources (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:processGenResources NO-SOURCE
Skipping task ':terminalmgmtinterface:processGenResources' as it has no source files and no previous output files.
Resolve mutations for :terminalmgmtinterface:genClasses (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:genClasses (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:genClasses UP-TO-DATE
Skipping task ':terminalmgmtinterface:genClasses' as it has no actions.
Resolve mutations for :terminalmgmtinterface:extractProto (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:extractProto (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:extractProto UP-TO-DATE
Caching disabled for task ':terminalmgmtinterface:extractProto' because:
  Build cache is disabled
Skipping task ':terminalmgmtinterface:extractProto' as it is up-to-date.
Resolve mutations for :terminalmgmtinterface:generateProperties (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:generateProperties (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:generateProperties SKIPPED
Skipping task ':terminalmgmtinterface:generateProperties' as task onlyIf 'Task is enabled' is false.
Resolve mutations for :terminalmgmtinterface:processResources (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:processResources (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:processResources UP-TO-DATE
Caching disabled for task ':terminalmgmtinterface:processResources' because:
  Build cache is disabled
Skipping task ':terminalmgmtinterface:processResources' as it is up-to-date.
Resolve mutations for :terminalmgmtinterface:checkSecuredTextSignatures (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:checkSecuredTextSignatures (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:checkSecuredTextSignatures SKIPPED
Skipping task ':terminalmgmtinterface:checkSecuredTextSignatures' as task onlyIf 'Task is enabled' is false.
Resolve mutations for :terminalmgmtinterface:generateJsonSchema2Pojo (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:generateJsonSchema2Pojo (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:generateJsonSchema2Pojo SKIPPED
Skipping task ':terminalmgmtinterface:generateJsonSchema2Pojo' as task onlyIf 'Task is enabled' is false.
Resolve mutations for :terminalmgmtinterface:compileJava (Thread[Execution worker,5,main]) started.
:terminalmgmtinterface:compileJava (Thread[Execution worker,5,main]) started.

> Task :terminalmgmtinterface:compileJava
Caching disabled for task ':terminalmgmtinterface:compileJava' because:
  Build cache is disabled
Task ':terminalmgmtinterface:compileJava' is not up-to-date because:
  Task has failed previously.
The input changes require a full rebuild for incremental task ':terminalmgmtinterface:compileJava'.
Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.
Compiling with toolchain 'C:\compiler\jdk-11.0.20.1+1'.

@ejona86
Copy link
Collaborator

ejona86 commented Mar 12, 2024

@dl6lr, remove the protoGenDir goo and apply the idea or eclipse plugins. The issue with IDEs is the folders have to exist already, and applying those plugins triggers workaround code in protobuf-gradle-plugin to create the folders eagerly.

@dl6lr
Copy link

dl6lr commented Mar 12, 2024

@ejona86 Thanks for your suggestion. I just tested it with no different results: No proto files are processed, no java files are generated. I changed the script to:

        // AC-2799 seems this is only needed for Eclipse to recognize those source folders
        //java {
            //srcDir "${project.ext.protoGenDir}/main/grpc"
            //srcDir "${project.ext.protoGenDir}/main/java"
        //}
        // AC-2799 end of eclipse source folder stuff

The eclipse plugin is already applied.

@ejona86
Copy link
Collaborator

ejona86 commented Mar 12, 2024

@dl6lr, seems your issue is different. Please open a separate issue (you can link to your initial comment here).

@dl6lr
Copy link

dl6lr commented Mar 12, 2024

@ejona86 thanks for your time. My issue seems to be caused by a (complex) multi project setup. I thought it is related.

@chop-suey
Copy link

chop-suey commented Mar 28, 2024

I have a similar problem: When I remove the java.srcDirs += ... part the proto-files are compiled and java/kotlin code is generated. The thing is, we also use another code generator which is not related to protobuf. It's generated sources still have to be added to java.srcDirs. But as soon as any entry is added to java.srcDirs protobuf refuses to compile the *.proto files.

(using com.google.protobuf:protobuf-gradle-plugin:0.9.4)

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

4 participants