Gradle file paths
Answered
Updated to IDEA 2021.1 and now all my gradle task filepaths are broken.
for example
File mainFile = new File("src/main/webapp/views/code/main.css")
now returns a FileNotFoundException
Please sign in to leave a comment.
Please see https://youtrack.jetbrains.com/issue/IDEA-265203#focus=Comments-27-4795223.0-0 and https://github.com/gradle/gradle/issues/16748 .
You cannot rely on the current directory in Gradle builds since Gradle can reuse the existing daemon that is started for another project and will have a completely different working directory.
Build logic must never rely on CWD. Use
Project.file,Project.projectDir,Project.buildDir,Project.rootDiretc instead. This applies to plugins as well. Plugins relying on CWD are broken and need to be fixed.Thanks. I have converted most to something like this...
File mainFile = new File("$projectDir/src/main/webapp/views/code/main.css")
which is working almost everywhere. This is the only code that doesnt seem to replace the variable.
task uploadToDevServer {
doLast {
ssh.settings {
knownHosts = allowAnyHosts
}
ssh.run {
session(remotes.webDevServer) {
put from: '$buildDir/build/libs/ROOT.war', into: '/mnt/backup'
}
}
}
}
The error says cant find file "$buildDir/build/libs/ROOT.war". Any reason why the variable replace isnt working on this one call?
https://discuss.gradle.org/ would be a better place for this question.
Looks like this works...