How do you get the path of the running script in groovy?

后端 未结 6 1731
悲哀的现实
悲哀的现实 2020-12-02 11:54

I\'m writing a groovy script that I want to be controlled via a properties file stored in the same folder. However, I want to be able to call this script from anywhere. Wh

6条回答
  •  悲哀的现实
    2020-12-02 12:38

    For gradle user

    I have same issue when I'm starting to work with gradle. I want to compile my thrift by remote thrift compiler (custom by my company).

    Below is how I solved my issue:

    task compileThrift {
    doLast {
            def projectLocation = projectDir.getAbsolutePath(); // HERE is what you've been looking for.
            ssh.run {
                session(remotes.compilerServer) {
                    // Delete existing thrift file.
                    cleanGeneratedFiles()
                    new File("$projectLocation/thrift/").eachFile() { f ->
                        def fileName=f.getName()
                        if(f.absolutePath.endsWith(".thrift")){
                            put from: f, into: "$compilerLocation/$fileName"
                        }
                    }
                    execute "mkdir -p $compilerLocation/gen-java"
                    def compileResult = execute "bash $compilerLocation/genjar $serviceName", logging: 'stdout', pty: true
                    assert compileResult.contains('SUCCESSFUL')
                    get from: "$compilerLocation/$serviceName" + '.jar', into: "$projectLocation/libs/"
                }
            }
        }
    }
    

提交回复
热议问题