project.buildscript.configurations.classpath
Reference: https://discuss.gradle.org/t/accessing-the-buildscript-classpath/5297/2
Project project = ProjectBuilder.builder().build()
FileUtils.copyInputStreamToFile(initialStream, targetFile);
ObjectMapper mapper = new ObjectMapper();
JavaType type = mapper.getTypeFactory().constructParametrizedType(Data.class, Data.class, Parameter.class);
Data<Parameter> dataParam = mapper.readValue(jsonString,type)
multiline.eachLine { line, count ->
if (count == 0) {
println "line $count: $line" // Output: line 0: Groovy is closely related to Java,
}
}
./gradlew clean build publish -m
new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
task unpackFiles(type: Copy) {
from zipTree("src/resources/thirdPartyResources.zip")
into "${buildDir}/resources"
}
s.trim().split("[\\W]+")
List<Integer> testCaseNumbers = new ArrayList<>();
report.testDetails.each {TestDetail t ->
t.testCaseNumbers.addAll(t.testCaseNumbers)
}
List<RallyTestCase> response = rallyProvider.getTestCases(testCaseNumbers.collect{x->x.toString()})
//converts [1,2,3] -> ["1","2","3"]
gradlew -b <filenam> task
test.afterTest { TestDescriptor td, TestResult tr ->
if (tr.resultType == ResultType.FAILURE) {
throw new Exception("$td failed")
}
}
private PrintStream sysOut;
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
@Before
public void setUpStreams() {
sysOut = System.out;
PrintStream contentOutputStream = new PrintStream(outContent)
System.setOut( new PrintStream( new TeeOutputStream(sysOut, contentOutputStream)));
}
@After
public void revertStreams() {
System.setOut(sysOut);
}
@Test
void test_(){
...
Assert.assertTrue(outContent.toString().contains("<Message>"));
}
new JsonSlurper().parseText(jsonAsText)
./gradlew myTask -PmyArg=hello
which can be used as
println "$project.myArg"
See https://stackoverflow.com/a/48370451/474377
new String( new ByteArrayOutputStream().toByteArray(), codepage );
See https://stackoverflow.com/questions/216894/get-an-outputstream-into-a-string