Michał Mielec
Michał Mielec

Reputation: 1651

ProtoBuffer generated classes by gradle are not visible in another module by IntelliJ

Hi I have one Gradle module which generates Protocol Buffer's classes according .proto files and packs it as .jar and another module which imports that jar. Generated classes are present in jar but IntelliJ does not see them.

Models module with .proto definitions:

description = ''

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "com.google.protobuf:protobuf-gradle-plugin:0.7.7"
    }
}

dependencies {
    compile 'com.google.protobuf:protobuf-java:2.6.1'
}

apply plugin: 'java'
apply plugin: "com.google.protobuf"
protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:2.6.1'
    }
}

Controllers module importing models.

description = ''

dependencies {
    compile project(':models')
}

The problem is when I try to use generated Models classes in Controllers IntelliJ doesn't see them.

Upvotes: 1

Views: 2267

Answers (1)

Michał Mielec
Michał Mielec

Reputation: 1651

Solution I found:

Adding to the build following lines:

sourceSets {
    main {
        java {
            srcDirs = ["src/main/java", "${protobuf.generatedFilesBaseDir}/main/java"]
        }
    }
}

Upvotes: 4

Related Questions