bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
192 stars 90 forks source link

Fix AssetConnection#connect for Java 17 #337

Open DKPillo opened 5 days ago

DKPillo commented 5 days ago

Using the following versions we run into an error with the less compiler:

When running the application locally the asset compilation using the standard less compiler failed with the following exception for each less asset:

Failed to open file JavaException: groovy.lang.MissingPropertyException: No such property: connected for class: asset.pipeline.utils.AssetConnection
failed to open file  asset:/path/to/asset.less   JavaException: groovy.lang.MissingPropertyException: No such property: connected for class: asset.pipeline.utils.AssetConnection

The reason is the call of AssetConnection#connect which sets the connected property of its parent class java.net.URLConnection. As this property is protected and the classes are not in the same namespace, this modification is not allowed.

I got the idea for the fix from Creating a Custom URL Connection

buildSrc/build.gradle

dependencies {
    implementation("org.grails:grails-gradle-plugin:6.2.0")
    implementation("com.bertramlabs.plugins:asset-pipeline-gradle:4.4.0")
    implementation("com.bertramlabs.plugins:less-asset-pipeline:4.4.0")
}

build.gradle

plugins {
    id "com.bertramlabs.asset-pipeline"
}
dependencies {
    assets "com.bertramlabs.plugins:less-asset-pipeline:4.4.0"
    runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:4.3.0"
    runtimeOnly "com.bertramlabs.plugins:less-asset-pipeline:4.4.0"
}
assets {
    developmentRuntime = true
    configOptions = [
            less: [
                    compiler: "standard"
            ]
    ]
}

buildSrc/build.gradle

grails {
    assets {
        less{
            compiler = '"tandard"
        }
    }
}
DKPillo commented 4 days ago

P.S. the following works as a hotfix:

bootRun {
    jvmArgs(
            // open java.net.URLConnection for asset.pipeline.utils.AssetConnection
            "--add-opens=java.base/java.net=ALL-UNNAMED"
    )
}