Gradle compileJava cannot find character from source file

I am new to Gradle, so there is a chance that I have missed something obvious here. I am working on using Gradle to automatically build our projects. I have dealt with most of them, but one of them causes me endless troubles. Since this is for my company, I cannot use any real code, but I will do my best to provide realistic pseudocode.

I am trying to compile a web application with flex front-end and java interface. Right now, I am focusing solely on creating a .war file with java in it, then I will go into flex compilation. When I run the following build.gradle script, it gives me countless "don't find character" 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 errors that occurred (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 InnerClass class is declared in the RenamedObject.java file along with the RenamedObject class. The character that he cannot find, OtherObject, not from .jar. This is the source file stored in /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 correctly created and launched via eclipse without any special settings. These errors occur during the task: compileJava after executing gradle war from the terminal.

Is there a reason Gradle will have a problem handling import source code from a subpackage like this? Am I just doing something wrong? Let me know if there is any additional information that might help, and I provided it if I can.

EDITOR: I have earned. All 130 errors were resolved with one change. If I add the full name of the package to OtherObject in extends, it looks like this:

 public class InnerClass extends com.companyName.teamName.projectName.core.release.subProjectName.projectVersion.superTypes.OtherObject implements Indexable<String>, Serializable { 

This one change made it all work, but I still don't understand the reason. This is not the only reference to OtherObject in the project, and it is not the only place where the inner class extends the class defined in another source package.

+14
source share
3 answers

Symptoms

Build failed using Gradle distribution ' https://services.gradle.org/distributions/gradle-2.8-bin.zip '

............

Called: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation error; see compiler error output for details.

Gradle Build Reports, so that you check the output of the Java compiler.

Check the output and see what class name it refers to output that it cannot solve.

 symbol: class <referenced_classname_here location: class <parent_classname_here 

Decision

Provide the fully qualified domain name wherever you refer to the class that is referred to as the character is not allowed.

In my case, I saw this when I defined an Inner class that extends a class in a library that I declared as a dependency in my build.gradle file.

PS:

I saw that the solution for this was already mentioned as a comment on the OP question.

I could not find this question because it did not have the right keywords for Google, and also did not have which further reduced its visibility.

The result of this - ONE FULL DAY DEPARTED, several strands of hair broke out before I realized this stupid hacker solution :(: (

I tried everything under the sun, which is remotely related to resolving dependencies, to fix this "dependency problem", which was never a problem with my code base.

We hope the Gradle team fixes this as soon as possible before more people rip out their hair.

Btw ... I love Gradle. :)

+12
source

Just adding to the knowledge base, but I had the same problem:

 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.

+1
source

I had the same problem today. If you are working with gradle, make sure your class is in src / main / java and not in src / test / java, otherwise your IDE (e.g. Eclipse) will say that all compilations are found, but when you try to compile using gradle, test the classes are not included by default (and this is normal!), so it will not compile.

0
source

Source: https://habr.com/ru/post/1212013/


All Articles