Skip to content

Instantly share code, notes, and snippets.

@breskeby
Created August 8, 2019 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breskeby/f2dd0a648e848d67734df9a79d8afbe6 to your computer and use it in GitHub Desktop.
Save breskeby/f2dd0a648e848d67734df9a79d8afbe6 to your computer and use it in GitHub Desktop.
non input system properties for test tasks
tasks.withType(Test).configureEach { Test testTask ->
def nonInputs = new InconsequentialSystemProperty()
testTask.jvmArgumentProviders.add(nonInputs)
def nonInputSystemProperty = { String key, value ->
nonInputs.props.put(key, value)
}
testTask.extensions.extraProperties.set("nonInputSystemProperty", nonInputSystemProperty)
}
class InconsequentialSystemProperty implements CommandLineArgumentProvider, Named {
final Map<String, Object> props = [:]
@Override
Iterable<String> asArguments() {
props.collect { key, value -> "-D${key}=${value}".toString() }
}
@Override
String getName() {
"inconsequentialSystemProperties"
}
}
// example usage
apply plugin:'java-libary'
test {
//Use TMPDIR as set on TeamCity
nonInputSystemProperty "java.io.tmpdir", System.getenv('TMPDIR') ?: System.getProperty("java.io.tmpdir")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment