[gradle] pathingJar doesn't work if classpath contains spaces

Issues that have occurred

The other day I wrote an article Run-app with grails and it doesn't boot, but I had a chance to build it with gradle, so I referred to the pathing Jar. I tried it with a pattern that puts it in and moves it, but apparently it does not work well if the classpath contains spaces. My PC was set up by a company employee in advance when I joined the company, but the full name is blank. So there is a space in the path to your home directory. orz

Coping

The classpath to be embedded in the jar is separated by spaces. Whitespace in the path seems to escape with% 20. Where you are collecting the paths of the pathingJar jar file, replace the spaces.

build.gradle


...Omission...
task pathingJar(type: Jar) {
    dependsOn configurations.runtime
    appendix = 'pathing'

    doFirst {
        manifest {
            attributes "Class-Path": configurations.runtime.files.collect {
                it.toURL().toString().replaceFirst(/file:\/+/, '/').replace(' ', '%20')
            }.join(' ')
        }
    }
}
...Omission...

Applied to Grails

Grails has a trick called pathingJar = true, but I also encountered a mysterious situation where it does not start. Therefore, write as follows. If I write a task with pathingJar as it is, I get angry that it already exists, so I chose the pathingJarEx task.

build.gradle


...Omission...
// grails {
// 	pathingJar = true
// }
task pathingJarEx(type: Jar) {
    dependsOn configurations.runtime
    appendix = 'pathing'

    doFirst {
        manifest {
            // Build the Class-Path for absolute paths based on runtime dependencies.
            attributes(
                'Class-Path': configurations.runtime.files.collect {
                    it.toURL().toString().replaceFirst(/file:\/+/, '/').replace(' ', '%20')
                }.join(' ')
            )
        }
    }
    exclude { it.file.absolutePath.contains('assetCompile') }
}
...Omission...
bootRun {
    ...Omission...
    dependsOn pathingJarEx
    doFirst {
        classpath = files("$buildDir/classes/main", "$buildDir/resources/main", "$projectDir/gsp-classes", pathingJarEx.archivePath)
    }
}
...Omission...

reference

It doesn't boot after run-app with grails

[Gradle] Dealing with Createprocess error = 206 [Note]

Recommended Posts

[gradle] pathingJar doesn't work if classpath contains spaces
Arrays.asList (int []). Contains (int) doesn't work
What to do if TextToSpeech doesn't work on Android 11
Check if you're using Databinding and it doesn't work