https://github.com/kyoripowered/mammoth
Helpful API for writing Gradle plugins
https://github.com/kyoripowered/mammoth
gradle gradle-plugin-development
Last synced: about 1 year ago
JSON representation
Helpful API for writing Gradle plugins
- Host: GitHub
- URL: https://github.com/kyoripowered/mammoth
- Owner: KyoriPowered
- License: mit
- Created: 2021-02-14T08:05:53.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-04-17T22:57:30.000Z (about 1 year ago)
- Last Synced: 2025-04-18T12:32:00.142Z (about 1 year ago)
- Topics: gradle, gradle-plugin-development
- Language: Java
- Homepage:
- Size: 503 KB
- Stars: 4
- Watchers: 4
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# mammoth
 [](license.txt)
## Plugin Utilities
The main component of `mammoth` is utility functions for developing Gradle plugins in java, plus `ProjectPlugin`, an interface for plugins for `Project` instances.
## Functional Testing
Mammoth provides test fixtures to enable functional testing of Gradle plugins. This architecture is designed for Java tests using JUnit 5, with the buildscripts for tested builds stored as classpath resources. This stands in contrast to Groovy functional tests, where the buildscript is written as a string directly in the test class.
### Annotations
Annotation | Purpose
--------------------------- | ------------------------------------------
`@GradleFunctionalTest` | Mark a test method as a functional test
`@GradleParameters` | Pass parameters to every Gradle invocation
`@TestVariant` | Declare a single variant of a tent, with a specific gradle version and extra parameters. Repeatable
`@TestVariantResource` | Declare a classpath resource to read additional variants from. Each line in the file is one variant, in the format `[:]`
### Usage
Example
Assuming there are files at `src/test/resources/com/example/myplugin/simpleBuild/in/build.gradle` and `src/test/resources/com/example/myplugin/simpleBuild/in/settings.gradle`, the following sets up a simple test that will run on both Gradle 6.9 and 7.1:
**com/example/myplugin/MyPluginTest.java**:
```java
/**
* A meta-annotation containing our test configuration.
*/
@GradleFunctionalTest
@GradleParameters({"--warning-mode", "all", "--stacktrace"}) // parameters for all variants
@TestVariant(gradleVersion = "6.9")
@TestVariant(gradleVersion = "7.1")
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
public @interface MyPluginTest {
}
```
**com/example/myplugin/MyPluginFunctionalTest.java**
```java
class MyPluginFunctionalTest {
@MyPluginTest
void simpleBuild(final TestContext ctx) {
ctx.copyInput("build.gradle");
ctx.copyInput("settings.gradle");
final BuildResult result = ctx.build("build"); // or anoher
assertEquals(TaskOutcome.SUCCESS, result.task(":build").getOutcome());
// Use any other methods on TestContext to help validate output.
}
}
```