Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 19888

How to customize JavaExec command line

$
0
0

Ended up doing something like that below but it doesn’t work with Gradle 6.6 (worked with 6.5.1). Any idea why it doesn’t work with 6.6 ? looks like commandLine only contains the executable now.

@CompileStatic
class ServerJavaExec extends JavaExec {

    private final Property<ExecResult> serverJavaExecResult;

    def serverName

    ServerJavaExec() {
         super()
         serverJavaExecResult = objectFactory.property(ExecResult.class);
    }

    @Override
    @TaskAction
    public void exec() {
        // drop the first item in commandLine, it is the executable (java.exe)
        def javaCommandArgsLine = commandLine.drop(1).join(' ')
        def javaCommand = "cmd /k start \"$serverName\" \"$executable\" $javaCommandArgsLine"

        getLogger().info "Executing $javaCommand ..."
        // >> Here I execute javaCommand, it eventually goes to process builder <<

        // immediately return a success result
        serverJavaExecResult.set([
            exitValue: 0,
            assertNormalExitValue: this,
            rethrowFailure: this
        ] as ExecResult);
    }

    @Override
    public Provider<ExecResult> getExecutionResult() {
       return serverJavaExecResult;
    }
}

Viewing all articles
Browse latest Browse all 19888

Trending Articles