通过gradle更改文件权限 [英] change file permission by gradle

查看:274
本文介绍了通过gradle更改文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了.jar文件并将其移至dir,但是我不明白以后如何更改该文件的权限。

I create .jar file and move it to dir, but I don't understand how I can change permission for this file after.

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
                'Implementation-Version': version,
                'Main-Class':'com.asd.App',
                'Class-Path': 'com.asd'
    }
    baseName = project.name + '-all'
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
    def file = file('/home/master/project/asd')
    fileMode = 755
    destinationDir = file
    with jar
}


推荐答案

创建 Exec 用于更改文件权限的任务。将此添加到您的 build.gradle 文件

Create an Exec Task to change file permission. Add this in your build.gradle file

task filepermission(type: Exec) {
    commandLine 'chmod', '700', '<file_path>'
}

使用 doLast 块运行它。您最终的 build.gradle 如下所示:

Run this using a doLast block. Your final build.gradle will look like this:

task filepermission(type: Exec) {
    commandLine 'chmod', '700', '<file_path>'
}

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
                'Implementation-Version': version,
                'Main-Class':'com.asd.App',
                'Class-Path': 'com.asd'
    }
    baseName = project.name + '-all'
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
    def file = file('/home/master/project/asd')
    fileMode = 755
    destinationDir = file
    with jar
    doLast {
        filepermission.execute()
    }
}

现在运行 gradle fatJar 应该更改文件许可权。确保在 filePermission 任务

now running gradle fatJar should change the file permission. Make sure you set proper path in the filePermission task

这篇关于通过gradle更改文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆