Gradle:如何引用另一个任务的输入?

时间:2018-05-28 19:19:25

标签: gradle

简短问题

在一个Gradle任务的配置中,如何引用另一个任务的输入?

我尝试过什么

考虑以下(人为的)样本build.gradle文件(存储在/tmp/foo下),我想在两个不同的任务中使用相同的任务输入值:

task task1 {
  def myInput = projectDir  // (or any other directory)
  inputs.dir(myInput).withPropertyName('t1Input')
  doLast {
    println myInput
  }
}

task task2 {
  dependsOn task1
  def myInput = task1.inputs.properties['t1Input']
  inputs.dir(myInput).withPropertyName('t2Input')
  doLast {
    println myInput
  }
}

task2中,我想使用与task1中相同的输入。但是,当我使用./gradlew --console=verbose --warning-mode=all task2运行此构建时,我得到:

> Task :task1 
/tmp/foo
> Task :task2 
A problem was found with the configuration of task ':task2'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.
 - No value has been specified for property 't2Input'.
null

t1Input task1无法通过task1.inputs.properties获取using System; using System.Threading.Tasks; using System.Collections.Generic; using Grpc.Core; using Etcdserverpb; using Google.Protobuf; using System.Runtime.CompilerServices; using Grpc.Auth; using Grpc.Core.Interceptors; namespace myproj.etcd { public class EtcdClient { Channel channel; KV.KVClient kvClient; string host; string username; string password; string authToken; Auth.AuthClient authClient; public EtcdClient(string host, string username, string password) { this.username = username; this.password = password; this.host = host; Authenticate(); // Expirementing with the token, trying to achieve my goal. channel = new Channel(host, ChannelCredentials.Create(ChannelCredentials.Insecure, GoogleGrpcCredentials.FromAccessToken(this.authToken))); // This works. //channel = new Channel(host, ChannelCredentials.Insecure); kvClient = new KV.KVClient(channel); } void Authenticate() { authClient = new Auth.AuthClient(new Channel(host,ChannelCredentials.Insecure)); var authRes = authClient.Authenticate(new AuthenticateRequest { Name = username, Password = password }); this.authToken = authRes.Token; } public string Get(string key) { try { var rangeRequest = new RangeRequest { Key = ByteString.CopyFromUtf8(key) }; var rangeResponse = kvClient.Range(rangeRequest); if (rangeResponse.Count != 0) { return rangeResponse.Kvs[0].Value.ToStringUtf8().Trim(); } } catch (Exception ex) { } return String.Empty; } } } 中名为Comparer<TKey>.Default.Compare(x.Item1, y.Item1); 的任务输入属性。

FWIW,我使用的是Gradle 4.6。

0 个答案:

没有答案