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

 

0
5 comments

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.

0

Build logic must never rely on CWD. Use Project.fileProject.projectDirProject.buildDirProject.rootDir etc instead. This applies to plugins as well. Plugins relying on CWD are broken and need to be fixed.

0

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?

 

 

 

0

https://discuss.gradle.org/ would be a better place for this question.

0

Looks like this works...

put from: buildDir.toString()+'/libs/ROOT.war', into: '/mnt/backup'
0

Please sign in to leave a comment.