Christopher Rucinski
Christopher Rucinski

Reputation: 4867

Gradle Copy Task causes file permission issue

Background

I have a JetBrains Plugin that I am developing. Recently, I moved from a Windows to a Ubuntu system. I am trying to set up everything correctly as before. Note: I am fairly new to Linux.

Issue

I am having an apparent file permission issue (as can be seen in the error section of this question) when I ran the following Gradle script. Note: Whenever I build the project, this Gradle script is automatically called. It also worked correctly on Windows.

If I comment out the copy{...} closure then everything works correctly. I just need to manually copy over the required file.

tasks.create(name: "copyJar_v${project['version']}") {

    group GROUP_CHROMATERIAL

    def mostCurrentJarFile = "ChroMATERIAL-${project['version']}.jar"

    // comment this out and there are not errors, but I need to do this copy manually
    copy {
        into '/'    // Copy into project's root folder
        from 'build/libs', {
            include mostCurrentJarFile
            rename mostCurrentJarFile, 'ChroMATERIAL.jar'
        }
    }

}

Error

FAILURE: Build failed with an exception.

* Where:
Build file 
  '/home/ciscorucinski/IdeaProjects/ChroMATERIAL/ChroMATERIAL/build.gradle' line: 100

* What went wrong:
A problem occurred evaluating project ':ChroMATERIAL'.
> Could not copy file '/home/ciscorucinski/IdeaProjects/ChroMATERIAL/ChroMATERIAL/build/libs/ChroMATERIAL-2.5.1.jar' to '/ChroMATERIAL.jar'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 0.139 secs
/ChroMATERIAL.jar (Permission denied)
오후 12:20:39: Task execution finished 'copyJar_v2.5.1'.

What I tried

I have been using the UI to modify the file permissions of the Plugin Project Folder within IdeaProjects.

  1. I gave everyone Create and delete files permissions and I Change Permissions for Enclosing Files...
  2. Everyone has Read and write access to files and Create and delete files access to folders.
  3. Clicked Change
  4. Run the Gradle script again ... same error message

Thoughts

Upvotes: 2

Views: 4278

Answers (1)

Justin Bowler
Justin Bowler

Reputation: 86

Well, it is true -- you cannot (and should not) copy files into the Root folder in a linux box. You could if you ran the script as sudo, but that is a bad idea.

Edited

Since you want to copy to the root of the project, you can use ${projectDir} or ${rootDir}.

Also, you should be able to do this without the hassle of a closure -- and it makes your script cleaner, IMHO -- by using the built in Copy task:

task copyClientLoc(type: Copy) {                  
    from "build/libs/"
    into "${rootDir}"
    include "ChroMATERIAL-${project['version']}.jar"
    fileMode = 0644
}

Upvotes: 3

Related Questions