0

I placed the output of protoc in a JAR and I want to use that JAR in my project. I added these lines to my build.gradle:

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
            srcDir 'src/main/resources/libs'
        }
    }
}

dependencies {
    compile files('src/main/resources/libs/bf-proto-api.jar')
}

When I try to use the generated class, the project doesn't compile. It says that my generated code (which is in src/main/resources/libs/bf-proto-api.jar) doesn't exist. Although IDEA does see src/main/resources/libs as a source directory, it provides no autocomplete.

c

Sebastian Lore
  • 357
  • 4
  • 23
  • It should work per https://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file. I would avoid mixing resources and library dependencies. The libraries normally do not reside under the resource roots and should be placed in `project root/lib` or some other location. – CrazyCoder Aug 20 '20 at 23:09
  • @CrazyCoder Got it. However, is it okay that my JAR contains the source code only? Gradle expects the jar to have java classes, doesn't it? I think maybe it's the reason it couldn't find any of the generated classes. – Sebastian Lore Aug 21 '20 at 13:17
  • Source jar dependencies will never work in Java, please see my answer to the similar question: https://stackoverflow.com/a/63001118/104891. – CrazyCoder Aug 21 '20 at 18:06

0 Answers0