Home > Blockchain >  Groovy compilation fails: Unable to load class 'org.grails.io.support.Resource'
Groovy compilation fails: Unable to load class 'org.grails.io.support.Resource'

Time:03-11

I'm developing a JavaFX application written in Groovy and using Gradle. When I started up my application in IntelliJ recently, it seemingly from out of the blue started failing to compile with the error:

Unable to load class 'org.grails.io.support.Resource'.

This is an unexpected error. Please file a bug containing the idea.log file.

This is from running the "run" gradle task.

This is my build file:

plugins {
    id 'groovy'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.7'
}

group 'redacted'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven { url "https://m2proxy.atlassian.com/repository/public" } // Atlassian repository
    maven { url "https://maven.atlassian.com/content/repositories/atlassian-public/"} // Atlassian public
    maven { url "https://download.java.net/maven/2/"}
}

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.5'

    // Logback log-annotation
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6'

    // https://mvnrepository.com/artifact/org.controlsfx/controlsfx
    implementation group: 'org.controlsfx', name: 'controlsfx', version: '11.1.0'

    testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'

    // ---- GPars concurrency lib ----
    // https://mvnrepository.com/artifact/org.codehaus.gpars/gpars
    implementation group: 'org.codehaus.gpars', name: 'gpars', version: '1.2.1'

    // ---- Jira Client ----
    // https://mvnrepository.com/artifact/com.atlassian.jira/jira-rest-java-client-app
    implementation group: 'com.atlassian.jira', name: 'jira-rest-java-client-app', version: '5.2.0'

    // https://mvnrepository.com/artifact/com.atlassian.jira/jira-rest-java-client-api
    implementation group: 'com.atlassian.jira', name: 'jira-rest-java-client-api', version: '5.2.0'

    // ---- Misc ----
    // https://mvnrepository.com/artifact/io.github.cdimascio/java-dotenv
    implementation group: 'io.github.cdimascio', name: 'java-dotenv', version: '5.2.2'

    // https://mvnrepository.com/artifact/org.jsoup/jsoup
    implementation group: 'org.jsoup', name: 'jsoup', version: '1.14.3'

    // ---- REST ----
    // https://mvnrepository.com/artifact/org.springframework/spring-web
    implementation group: 'org.springframework', name: 'spring-web', version: '3.0.2.RELEASE'

    // https://mvnrepository.com/artifact/org.grails/grails-datastore-rest-client
    implementation group: 'org.grails', name: 'grails-datastore-rest-client', version: '6.1.9.RELEASE'

    // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
    implementation group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'

    // https://mvnrepository.com/artifact/net.dongliu/requests
    implementation group: 'net.dongliu', name: 'requests', version: '5.0.8'

    // https://mvnrepository.com/artifact/io.jsondb/jsondb-core
    implementation group: 'io.jsondb', name: 'jsondb-core', version: '1.0.115-j11'
}

test {
    useJUnitPlatform()
}

javafx {
    modules = ['javafx.controls', 'javafx.fxml']
    version = '11.0.2'
}

mainClassName = 'redacted'

Has anyone seen this before? The things I've tried:

  • Invalidating caches in IntelliJ
  • Clean Rebuild
  • Rollback code to a point I know compiled.
  • Update gradlew to use gradle 7.4

UPDATE

I seem to have found the culprit. My company has recently changed stuff related to how we build our projects, which requires using a init.gradle file in the .gradle/ folder, which contains some standard repository definitions. This is the content (with company repositories redacted):

allprojects {
    apply plugin: 'java'
    apply plugin: 'maven-publish'
    buildscript {
        repositories {
            maven {
                url "https://<redacted>"
                credentials {
                    username mavenUser
                    password mavenPassword
                }
            }
        }
    }
    repositories {
        mavenLocal()
        maven {
            url "https://<redacted>"
            credentials {
                username mavenUser
                password mavenPassword
            }
        }
    }
    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
            }
        }
        repositories {
            maven {
                credentials {
                    username mavenUser
                    password mavenPassword
                }
                url "https://<redacted>"
            }
        }
    }
}

Removing it fixed the problem for the project in question, but will obviously not work for all the other work related projects. So the question remains...how does this cause such an error?

UPDATE 2

I have not exactly found the source of the error, but it seems to have something to do with the repositories being declared in a wrong way. To fix this, one can call clear() in the project build.gradle file at the top of the repositories definition, effectively ignoring what's declared in init.gradle. So, just update the repositories {} clause to:

repositories {
    clear() // This is needed in order for init.gradle to not cause errors
    mavenCentral()
    maven { url "https://m2proxy.atlassian.com/repository/public" } // Atlassian repository
    maven { url "https://maven.atlassian.com/content/repositories/atlassian-public/"} // Atlassian public
    maven { url "https://download.java.net/maven/2/"}
}

CodePudding user response:

I have not exactly found the source of the error, but it seems to have something to do with the repositories being declared in a wrong way. To fix this, one can call clear() in the project build.gradle file at the top of the repositories definition, effectively ignoring what's declared in init.gradle. So, just update the repositories closure to:

repositories {
    clear() // This is needed in order for init.gradle to not cause errors
    mavenCentral()
    maven { url "https://m2proxy.atlassian.com/repository/public" } // Atlassian repository
    maven { url "https://maven.atlassian.com/content/repositories/atlassian-public/"} // Atlassian public
    maven { url "https://download.java.net/maven/2/"}
}
  • Related