代码之家  ›  专栏  ›  技术社区  ›  Roman Nikitchenko

如何在Gradle中复制目录保留符号链接?

  •  0
  • Roman Nikitchenko  · 技术社区  · 6 年前

    下面的gradle任务复制目录,但解析所有符号链接。这是不可接受的。我想保存。

    task test {
        doLast {
            copy {
                from 'source'
                to 'destination'
            }
        }
    }
    

    怎么办?

    1 回复  |  直到 6 年前
        1
  •  4
  •   ToYonos    6 年前

    有一个 open issue

    现在你可以检测符号链接,也许可以手动创建它

    import java.nio.file.FileSystems
    import java.nio.file.Files
    import java.nio.file.Path
    
    copy {
        from $source
        into $destination
        eachFile { details ->
            Path pathFile = FileSystems.getDefault().getPath(details.file.path)
            if(Files.isSymbolicLink(pathFile)) {
                details.exclude()
                commandLine 'ln', '-s', Files.readSymbolicLink(pathFile), "$destination/${details.relativePath}
            }
        }
    }