Reputation: 2429
I have a gradle project in big-project/
and a sub-project in big-project/lib/
.
In big-project/
's big.project.Main
class I import big.project.lib.Utils
, which is defined in the big-project/lib/
sub-project.
When I try to run gradle build
, this is what happens:
:lib:
compileJava UP-TO-DATE
:lib:processResources UP-TO-DATE
:lib:classes UP-TO-DATE
:lib:jar
:compileJava
big-project/src/main/java/big/project/Main.java:3: error: package big.project.lib not exist
import big.project.lib.Utils;
^
1 error
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 6.243 secs
For some reason, gradle compiles the code of the subproject, and then decides to ignore it. How do I fix that?
These are my gradle files:
big-project/settings.gradle
:
include 'lib'
big-project/build.gradle
:
evaluationDependsOnChildren()
allprojects {
apply plugin: 'java'
sourceCompatibility = '1.8'
version = '1.0'
group = 'big.project'
}
apply plugin: 'war'
dependencies {
compile project(':lib')
}
big-project/lib/build.gradle
is empty
Upvotes: 1
Views: 1007
Reputation: 2429
TL;DR: My big-project/lib/src
folder wasn't set up correctly (source code was in the wrong sub directory). As this answer states, Java sources need to be in src/main/java
.
Thanks to comments on the question I was able to look in the right place for a solution. As suggested, I looked at a working sample project. As I was using Eclipse, I generated a new Gradle project based on the flat-java-multiproject
sample. This enabled me to eliminate my build.gradle
files as the source of the error.
Next, I decided to inspect the build/
artifacts of the lib/
project and discovered that the .jar
file did not contain any .class
files. That explains the compiler error I reported in the question. This caused my to see if all .java
sources were in the right place, and as mentioned above, they weren't. Fixing this, fixed the compiler error.
The whole crux was that while I was writing my code in eclipse, all references to the lib
project's classes seemed to be found.
Upvotes: 1