I'm new with Gradle, so there's a chance that I am missing something obvious here. I am working on using Gradle for automated building of our projects. I've tackled most of them, but one is causing me unending trouble. Since this is for my company, I can't share any real code, but I will do my best to provide realistic pseudo-code.
I am attempting to compile a web application with a flex front-end and java back-end. Right now, I am focused solely on creating a .war file with the java in it, then I will move into the flex compilation. When I run the following build.gradle script, it gives me countless "cannot find symbol" errors.
apply plugin: 'eclipse'
apply plugin: 'war'
sourceCompatibility = 1.6
repositories {
mavenCentral()
}
sourceSets.main.java.srcDir 'src'
sourceSets.main.resources.srcDir 'src'
webAppDirName = "WebContent"
war.archiveName "Gradle_test.war"
dependencies {
compile fileTree(dir: 'WebContent/WEB-INF/lib', include: '*.jar')
providedCompile 'org.apache.tomcat:catalina:6.0.13'
providedCompile 'org.apache.tomcat:dbcp:6.0.13'
}
An example of the errors that were occurring (with fake package and class names):
/Users/user/Documents/eclipse/ProjectName/src/com/companyName/teamName/projectName/core/release/subProjectName/projectVersion/RenamedObject.java:385: cannot find symbol
symbol : class OtherObject
location: class com.companyName.teamName.projectName.core.release.subProjectName.projectVersion.RenamedObject
public class InnerClass extends OtherObject implements Indexable<String>, Serializable {
The class InnerClass is declared within the RenamedObject.java file along with the RenamedObject class. The symbol it cannot find, OtherObject, is not from a .jar. It is a source file stored at /Users/user/Documents/eclipse/ProjectName/src/com/companyName/teamName/projectName/core/release/subProjectName/projectVersion/superTypes/OtherObject.java
. The object is imported at the top of RenamedObject.java and can be built and run properly via eclipse without any special settings. These errors occur during the :compileJava task after executing gradle war
from terminal.
Is there any reason that Gradle would have an issue with handling source imports from a sub-package like this? Am I just doing something wrong? Let me know if there is any more info that can help and I will provide it if I can.
EDIT: I got it to work. All 130 of the errors were resolved with one change. If I add the fully qualified package name to OtherObject in the extends, so it looks like this:
public class InnerClass extends com.companyName.teamName.projectName.core.release.subProjectName.projectVersion.superTypes.OtherObject implements Indexable<String>, Serializable {
That one change made it all work, but I still don't understand the reason. That is not the only reference to OtherObject in the project and it is not the only place that an inner class extends a class defined in another source package.
Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.8-bin.zip'
... .... .....
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
The Gradle Build Reports that you should check the compiler Java Output.
Check the output and see which class name it cites in the output which it is unable to resolve.
symbol: class <referenced_classname_here
location: class <parent_classname_here
Provide the Fully Qualified Domain Name wherever you reference the class that is mentioned as the symbol not resolved.
In my case, I have seen this when I defined an Inner Class which extends a class in a library that I had declared as a dependency in my build.gradle.
P.S:
I have seen that the solution for this has already been mentioned as a comment to the question by the OP.
I could not find this question since it did not have the right keywords for google and also there was no accepted solution which further reduced its visibility.
The result of this is ONE FULL DAY WASTED, several strands of hair plucked out before I realized this stupid hackish solution :( :(
I have tried everything under the Sun that is remotely related to dependency resolution to fix this "dependency issue" which was never an issue with my codebase.
Hope the Gradle Team fixes this ASAP before more people pluck their hair.
Btw... I Love Gradle. :)
Just adding to the knowledge base, but I had just the same type of problem with:
public static class GetNetworkInterfacesCallable implements java.util.concurrent.Callable<java.util.Set<java.net.InetAddress>> {
public GetNetworkInterfacesCallable(String networkPrefix) {
this.networkPrefix=networkPrefix;
}
@Override public Set<InetAddress> call() throws Exception {
Thread.currentThread().setName(getClass().getName());
return null; //myInetAddresses(networkPrefix);
}
final String networkPrefix;
}
Using gradle 2.9 and 2.10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With