Gradle Eclipse build error

I’m having an issue with one of my gradle projects in eclipse. When I attempt to build or refresh dependencies within eclipse, I’m receiving the error below. I’m running Eclipse under Java 8 but the project is Java 6. Gradle builds the project fine from the command line (Gradle 2.8, Java 6, 7, 8)

[Fatal Error] :2:140: External DTD: Failed to read external DTD ‘application_1_2.dtd’, because ‘http’ access is not allowed due to restriction set by the accessExternalDTD property.

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘/…/build.gradle’ line: 10
  • What went wrong:
    A problem occurred evaluating root project ‘myrpoject’.

Failed to apply plugin [id ‘ear’]
External DTD: Failed to read external DTD ‘application_1_2.dtd’, because ‘http’ access is not allowed due to restriction set by the accessExternalDTD property.

Are you using any Gradle Eclipse integration e.g. Buildship or the Pivotal Gradle plugin?

Using the Pivotal / STS version. I could not get the Buildship version to automatically refresh dependencies.

The STS plugin it maintained by Pivotal. If you encounter an issue, you’d need to report to their forum. Keep in mind that Pivotal will stop supporting their plugin in the next couple of months.

Side note: Neither Buildship nor the STS Gradle plugin currently provide automatic refresh of dependencies if you change the build file.

The STS Gradle plugin has a menu option to ‘Refresh Dependencies’ and also a preference to ‘Enable automatic refresh’. Does the Buildship plugin offer this functionality?

Oh really? Didn’t know about the preference option. As far as I know Buildship does not offer automatic refresh.

What is the suggested way of refreshing dependencies in eclipse with Buildship? I was stuck using the command line to rebuild the eclipse artifacts using the following process every time I add a new dependency.

  1. gradle compile
  2. gradle eclipse
  3. Refresh project in eclipse.

There really has to be a better way than this

Once you imported the project into Buildship, there’s no more need to run gradle eclipse anymore. Generally speaking you don’t actually need to use the Gradle Eclipse plugin at all if your project doesn’t require any customizations.

The workflow would look as such:

  1. Import project into Buildship
  2. Add a new dependency to the build.gradle file within Buildship
  3. Trigger the “Refresh dependency” option in Buildship

Jared, after importing a Gradle project into Eclipse, you can refresh the Eclipse project when dependencies, source sets, etc. change via context menu on the project (or by pressing F5 while the project is select in the project explorer).

Automatic refresh is currently not supported, but it is on our list of things to do. It will require some changes in the Gradle Tooling API first.

The problem is caused by the XML parser the Gradle wrapper uses to read the .XML files in the project to import. Once the Gradle wrapper runs in Eclipse’s JVM, the system properties to control the XML parser have to be defied in the eclipse.ini file.
In eclipse.ini file add the lines:
-Djavax.xml.accessExternalSchema=all
-Djavax.xml.accessExternalDTD=all
They allow the XML parser download the DTD/XSD defined in the XML to parse.

Based on: https://www.baselogic.com/2016/08/09/failed-read-schema-document-xjc-xsd-file-access-allowed-due-restriction-set-accessexternalschema-property/