Change gradle file resolution

I am creating a .jar file and moving it to a directory, but I do not understand how I can change the resolution 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
}
+6
source share
4 answers

Create a task Execto change the file resolution. Add this to your build.gradlefile

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

Run it using the block doLast. Your last build.gradlewill 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()
    }
}

Now the launch gradle fatJarshould change the file resolution. Make sure you set the correct path in the taskfilePermission

+5
source

If you want to embed it in an existing custom task, you can use Project.exec(Action<? super ExecSpec> action).

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

project , AbstractTask.getProject().

+6

. , , :

distributions {
    main {
        contents {
            from fileTree('src/main/scripts'), {
                filesMatching('myscript') { mode = 0744 }
            }
        }
    }
}
+1

Linux. Windows Windows, Linux. , . , "0" , .

, , , tar Windows, zip , zip Windows .

0

Source: https://habr.com/ru/post/1654104/


All Articles