简体   繁体   中英

How to call a gradle method from a groovy script

Is it possible to call a 'ext.' gradle method from a groovy script?

Here is the an example of a gradle ext.method I am trying to call (File: codec.gradle)

ext.encrypt = { param ->
  generateKey()
  String encryptedMessage = encryptAES(param)

  println("--ENCRYPTION--")
  println("password: "+param)
  println("key: "+key)
  println("Encrypted message: "+encryptedMessage)

  return encryptedMessage
}

What i want to do is call it from a groovy script like this one: (File: TestGradleReference.groovy)

I am imagining something like this

apply from: "script/codec.gradle"
String encryptVal = project.encrypt('password')
println("Encrypted value: " + encryptVal)

however this doesn't work

What is the best way (if possible) to call a gradle method from a groovy script?

This is actually not possible

ext.encrypt

are only accessible from gradle files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM