2016-09-09 2 views
4

.jar 파일을 만들고 dir로 이동하지만이 파일에 대한 사용 권한을 어떻게 바꿀 수 있는지 이해할 수 없습니다.gradle에 의한 파일 변경 권한

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 
} 
+0

왜 처음부터 올바른 모드로 파일을 만들지 않습니까? – Henry

답변

4

Exec 파일을 변경하는 작업을 만듭니다.

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

실행 이것을 doLast 블록을 사용하여 build.gradle 파일이 추가. 최종 build.gradle는 다음과 같이 표시됩니다

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 작업에서 올바른 경로를 설정했는지 확인하십시오.

+0

고마워,하지만 내 작업의 본문에서 어떻게 사용할 수 있습니까? – dzrkot

3

기존 사용자 지정 작업에 포함 시키려면 Project.exec(Action<? super ExecSpec> action)을 사용하십시오. 이 AbstractTask.getProject()에서 오기 때문에

task changePermission { 
    doLast { 
    project.exec { 
     commandLine('chmod', '+x', '<fileLocation>') 
    } 
    } 
} 

project는 대부분의 작업 구현에서 사용할 수 있습니다.