0

I upgraded to Eclipse 2020-06 a couple months ago, and ever since then my Gradle files appear to be validated as Java files rather than as Gradle files:

Eclipse Problems view showing multiple Java Problems in my Gradle files

They also have the Java class file icon next to their name in the explorer, but I'm not sure that was not the case before:

Eclipse Project Explorer view apparently showing Gradle files as Java files

As an example, here is failingBuild.gradle:

defaultTasks 'build'

task build {
    doLast {
        println "stopping the build by throwing an exception..."
        throw new GradleException('deliberately failing the build')
        println "this should not be printed"
    }
}

My Gradle Unit Tests also have been failing because ClassLoader.getSystemResource() returns null when attempting to get these files as System Resources.

As far as I know, I haven't changed anything about Eclipse other than update it. I'd really like Eclipse to process these Gradle files properly again, i.e. as something other than Java files.

Since people asked for it, the project structure:

enter image description here

These gradle files are part of our unit tests. they are used to test whether our product can properly start gradle-based build scripts and verify the build succeeded or failed. As such, they are located in a source directory. One thing I've noticed is that these scripts can't be loaded as system resources with the below code:

buildFile = new File(ClassLoader
  .getSystemResource("be/ikan/scm4all/util/builders/gradle/testBuild.gradle")
                    .getPath());

This may or may not be relevant.

Nzall
  • 3,439
  • 5
  • 29
  • 59
  • 1
    Without being able to replicate the behaviour maybe it is worth a try to redefine the file association of eclipse. Usually this is under `Preferences → General → Editor → File Associations.` Under file types see if you can find the .gradle extension and check if it is set to the Gradle Built Script Editor. (Alternative path: Window→ Preferences→ Workbench→ File Associations) Could it be that one of your gradle plugins is not compatble with the new eclipse version? Maybe take a look at the marketplace and search for an alternative. – Kilian Sep 15 '20 at 11:14
  • @Kilian Gradle files are associated to the Gradle Build Script Editor, as recommended. My installed plugins are just Buildship: Eclipse Plug-ins for Gradle, version 3.1.4.v20200326-1743. However, it appears like this is an older version than my Eclipse IDE for Enterprise Java Developers, which is given as 4.16.0.20200615+-1200. – Nzall Sep 15 '20 at 11:42
  • Have you changed anything in the project structure, possibly moved gradle tasks around? Also, can you run the gradle tasks from CLI? What does that show? – Lefty G Balogh Sep 15 '20 at 15:07
  • Do you have a sample project available somewhere so that someone can test it? – smac89 Sep 15 '20 at 17:51
  • Could you please add the project directory structure to the question? It looks like these gradle files are in a Java-source folder. How do you import the projects? With buildship? – dpr Sep 18 '20 at 11:10
  • 1
    In general it's best practice to keep java sources and non-java files apart. Usually there is a dedicated source folder for resources... Maybe check the "content types" setting in Eclipse. – dpr Sep 18 '20 at 13:47
  • Check what plugins you have installed. One might not be compatible with your current version. If a plugin isn't compatible, it could possibly be breaking something. – Nebula Sep 20 '20 at 13:39

1 Answers1

0

You can try out the following steps based on this post:

  1. cleanup project: Project > Clean...
  2. refresh gradle project: right click on your project > Gradle > Refresh Gradle Project
  3. import the project again as a gradle project: File > Import > Existing Gradle Project

Otherwise can you try to create a new gradle file? What happens? Have you installed the Gradle Buildship Tool? Can you update the tool?

flaxel
  • 4,173
  • 4
  • 17
  • 30
  • As I mentioned, Buildship is installed. It's not a gradle project, it's just a Java project that happens to contain Gradle files in one of the source directories. – Nzall Sep 22 '20 at 07:37