Java Code Examples for org.gradle.testkit.runner.GradleRunner#withGradleVersion()

The following examples show how to use org.gradle.testkit.runner.GradleRunner#withGradleVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GradleBuild.java    From spring-javaformat with Apache License 2.0 6 votes vote down vote up
public GradleRunner prepareRunner(String... arguments) throws IOException {
	copyFolder(this.source.getAbsoluteFile().toPath(), this.projectDir.toPath());
	File buildFile = new File(this.projectDir, "build.gradle");
	String scriptContent = new String(Files.readAllBytes(buildFile.toPath())).replace("{version}",
			getSpringFormatVersion());
	Files.write(buildFile.toPath(), scriptContent.getBytes(Charsets.UTF_8));
	GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir).withDebug(true);
	if (this.gradleVersion != null) {
		gradleRunner.withGradleVersion(this.gradleVersion);
	}
	List<String> allArguments = new ArrayList<>();
	allArguments.add("-PpluginClasspath=" + getPluginClasspath());
	allArguments.add("-PspringFormatVersion=" + getSpringFormatVersion());
	allArguments.add("--stacktrace");
	allArguments.addAll(Arrays.asList(arguments));
	return gradleRunner.withArguments(allArguments);
}
 
Example 2
Source File: FunctionalTestBase.java    From gradle-download-task with Apache License 2.0 5 votes vote down vote up
/**
 * Create a gradle runner using the given build file
 * @param buildFile the build file
 * @return the gradle runner
 * @throws IOException if the build file could not written to disk
 */
protected GradleRunner createRunnerWithBuildFile(String buildFile) throws IOException {
    FileUtils.writeStringToFile(this.buildFile, buildFile, StandardCharsets.UTF_8);

    writePropertiesFile();
    GradleRunner runner = GradleRunner.create()
        .withPluginClasspath()
        .withProjectDir(testProjectDir.getRoot());
    if (gradleVersion != null) {
        runner = runner.withGradleVersion(gradleVersion);
    }
    return runner;
}