pborgen
(Paul B)
August 31, 2017, 9:30pm
1
I am writing some custom tasks in Java. I am having a hard time finding any code examples. All the ones I have found are in groovy. I wrote a junit test and I am trying to figure out how to call my custom task. Any suggestions?
Project project = ProjectBuilder.builder().build();
Task task = project.task(“FileHeaderVerify”, ???);
sterling
(Sterling Greene)
September 1, 2017, 12:13am
2
I wouldn’t use ProjectBuilder for testing that your task works. It doesn’t simulate enough of a real Gradle runtime to make it work.
Take a look at this guide (specifically the functional test section): https://guides.gradle.org/testing-gradle-plugins/#functional-tests
I wouldn’t personally write functional tests in Java, but there’s an example bundled in the Gradle distribution:
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.sample;
// START SNIPPET functional-test-junit
import org.gradle.testkit.runner.BuildResult;
This file has been truncated. show original