Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit 82250f4

Browse files
committed
Gradle plugin example
Signed-off-by: Tom Sellman <[email protected]>
1 parent 4f07101 commit 82250f4

26 files changed

+275
-879
lines changed

Makefile

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,21 @@
1-
2-
config ?= compileClasspath
3-
4-
ifdef module
5-
mm = :${module}:
6-
else
7-
mm =
8-
endif
1+
# Build the plugin
2+
assemble:
3+
./gradlew assemble
94

105
clean:
116
rm -rf .nextflow*
127
rm -rf work
138
rm -rf build
14-
rm -rf plugins/*/build
159
./gradlew clean
1610

17-
compile:
18-
./gradlew :nextflow:exportClasspath compileGroovy
19-
@echo "DONE `date`"
20-
21-
22-
check:
23-
./gradlew check
24-
25-
26-
#
27-
# Show dependencies try `make deps config=runtime`, `make deps config=google`
28-
#
29-
deps:
30-
./gradlew -q ${mm}dependencies --configuration ${config}
31-
32-
deps-all:
33-
./gradlew -q dependencyInsight --configuration ${config} --dependency ${module}
34-
35-
#
36-
# Refresh SNAPSHOTs dependencies
37-
#
38-
refresh:
39-
./gradlew --refresh-dependencies
40-
41-
#
42-
# Run all tests or selected ones
43-
#
11+
# Run plugin unit tests
4412
test:
45-
ifndef class
46-
./gradlew ${mm}test
47-
else
48-
./gradlew ${mm}test --tests ${class}
49-
endif
50-
51-
assemble:
52-
./gradlew assemble
53-
54-
#
55-
# generate build zips under build/plugins
56-
# you can install the plugin copying manually these files to $HOME/.nextflow/plugins
57-
#
58-
buildPlugins:
59-
./gradlew copyPluginZip
60-
61-
#
62-
# Upload JAR artifacts to Maven Central
63-
#
64-
upload:
65-
./gradlew upload
66-
13+
./gradlew test
6714

68-
upload-plugins:
69-
./gradlew plugins:upload
15+
# Install the plugin into local nextflow plugins dir
16+
install:
17+
./gradlew install
7018

71-
publish-index:
72-
./gradlew plugins:publishIndex
19+
# Publish the plugin
20+
release:
21+
./gradlew releasePlugin

README.md

Lines changed: 37 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,79 @@
1-
# nf-hello plugin
2-
1+
# nf-hello plugin
2+
33
This project contains a simple Nextflow plugin called `nf-hello` which provides examples of different plugin extensions:
44

55
- A custom trace observer that prints a message when the workflow starts and when the workflow completes
66
- A custom channel factory called `reverse`
77
- A custom operator called `goodbye`
88
- A custom function called `randomString`
99

10-
NOTE: If you want to use this project as a starting point for a custom plugin, you must rename the `plugins/nf-hello` folder and update `settings.gradle` with your plugin name.
10+
NOTE: If you want to use this project as a starting point for a custom plugin, you must rename the `plugins/nf-hello`
11+
folder and update `settings.gradle` with your plugin name.
1112

12-
See the [Nextflow documentation](https://nextflow.io/docs/latest/plugins.html) for more information about developing plugins.
13+
See the [Nextflow documentation](https://nextflow.io/docs/latest/plugins.html) for more information about developing
14+
plugins.
1315

1416
## Plugin structure
15-
16-
- `settings.gradle`
17-
18-
Gradle project settings.
19-
20-
- `plugins/nf-hello`
21-
22-
The plugin implementation base directory.
23-
24-
- `plugins/nf-hello/build.gradle`
25-
26-
Plugin Gradle build file. Project dependencies should be added here.
2717

28-
- `plugins/nf-hello/src/resources/META-INF/MANIFEST.MF`
29-
30-
Manifest file defining the plugin attributes e.g. name, version, etc. The attribute `Plugin-Class` declares the plugin main class. This class should extend the base class `nextflow.plugin.BasePlugin` e.g. `nextflow.hello.HelloPlugin`.
18+
- `settings.gradle`
3119

32-
- `plugins/nf-hello/src/resources/META-INF/extensions.idx`
33-
34-
This file declares one or more extension classes provided by the plugin. Each line should contain the fully qualified name of a Java class that implements the `org.pf4j.ExtensionPoint` interface (or a sub-interface).
20+
Gradle project settings.
3521

36-
- `plugins/nf-hello/src/main`
22+
- `src/main`
3723

38-
The plugin implementation sources.
24+
The plugin implementation sources.
3925

40-
- `plugins/nf-hello/src/test`
26+
- `src/test`
4127

42-
The plugin unit tests.
28+
The plugin unit tests.
4329

4430
## Plugin classes
4531

4632
- `HelloConfig`: shows how to handle options from the Nextflow configuration
4733

48-
- `HelloExtension`: shows how to create custom channel factories, operators, and fuctions that can be included into pipeline scripts
34+
- `HelloExtension`: shows how to create custom channel factories, operators, and fuctions that can be included into
35+
pipeline scripts
4936

5037
- `HelloFactory` and `HelloObserver`: shows how to react to workflow events with custom behavior
5138

5239
- `HelloPlugin`: the plugin entry point
5340

54-
## Unit testing
55-
56-
To run your unit tests, run the following command in the project root directory (ie. where the file `settings.gradle` is located):
41+
## Building
5742

43+
To compile and assemble the plugin, run the following command in the project root directory:
5844
```bash
59-
./gradlew check
45+
make assemble
6046
```
6147

62-
## Testing and debugging
63-
64-
To build and test the plugin during development, configure a local Nextflow build with the following steps:
48+
## Unit testing
6549

66-
1. Clone the Nextflow repository in your computer into a sibling directory:
67-
```bash
68-
git clone --depth 1 https://github.com/nextflow-io/nextflow ../nextflow
69-
```
70-
71-
2. Configure the plugin build to use the local Nextflow code:
72-
```bash
73-
echo "includeBuild('../nextflow')" >> settings.gradle
74-
```
75-
76-
(Make sure to not add it more than once!)
77-
78-
3. Compile the plugin alongside the Nextflow code:
79-
```bash
80-
make assemble
81-
```
82-
83-
4. Run Nextflow with the plugin, using `./launch.sh` as a drop-in replacement for the `nextflow` command, and adding the option `-plugins nf-hello` to load the plugin:
84-
```bash
85-
./launch.sh run nextflow-io/hello -plugins nf-hello
86-
```
50+
To run your unit tests, run the following command in the project root directory:
51+
```bash
52+
make test
53+
```
8754

88-
## Testing without Nextflow build
55+
## Testing with Nextflow
8956

90-
The plugin can be tested without using a local Nextflow build using the following steps:
57+
The plugin can be tested without a local Nextflow installation:
9158

92-
1. Build the plugin: `make buildPlugins`
93-
2. Copy `build/plugins/<your-plugin>` to `$HOME/.nextflow/plugins`
94-
3. Create a pipeline that uses your plugin and run it: `nextflow run ./my-pipeline-script.nf`
59+
1. Build and install the plugin to your local Nextflow installation: `make install`
60+
2. Create a pipeline that uses your plugin and run it: `nextflow run ./my-pipeline-script.nf`
9561

9662
## Package, upload, and publish
9763

98-
The project should be hosted in a GitHub repository whose name matches the name of the plugin, that is the name of the directory in the `plugins` folder (e.g. `nf-hello`).
99-
10064
Follow these steps to package, upload and publish the plugin:
10165

102-
1. Create a file named `gradle.properties` in the project root containing the following attributes (this file should not be committed to Git):
66+
1. In `build.gradle` make sure that
67+
* `github.repository` matches the repository of the plugin
68+
* `github.indexUrl` points to your fork of the plugins index repository.
69+
70+
2. Create a file named `$HOME/.gradle/gradle.properties`, where $HOME is your home directory. Add the following properties:
10371

104-
* `github_organization`: the GitHub organisation where the plugin repository is hosted.
105-
* `github_username`: The GitHub username granting access to the plugin repository.
106-
* `github_access_token`: The GitHub access token required to upload and commit changes to the plugin repository.
107-
* `github_commit_email`: The email address associated with your GitHub account.
72+
* `github_username`: The GitHub username granting access to the plugin repository.
73+
* `github_access_token`: The GitHub access token required to upload and commit changes to the plugin repository.
74+
* `github_commit_email`: The email address associated with your GitHub account.
10875

109-
2. Use the following command to package and create a release for your plugin on GitHub:
110-
```bash
111-
./gradlew :plugins:nf-hello:upload
112-
```
76+
3. Use the following command to package and create a release for your plugin on GitHub: `make release`
11377

114-
3. Create a pull request against [nextflow-io/plugins](https://github.com/nextflow-io/plugins/blob/main/plugins.json) to make the plugin accessible to Nextflow.
78+
4. Create a pull request against [nextflow-io/plugins](https://github.com/nextflow-io/plugins/blob/main/plugins.json) to
79+
make the plugin accessible to Nextflow.

build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id 'io.nextflow.nextflow-plugin' version '0.0.1-alpha'
3+
}
4+
5+
// plugin version
6+
version = '0.6.0'
7+
8+
nextflowPlugin {
9+
// minimum nextflow version
10+
nextflowVersion = '24.11.0-edge'
11+
12+
// plugin metadata
13+
provider = 'nextflow'
14+
className = 'nextflow.hello.HelloPlugin'
15+
extensionPoints = [
16+
'nextflow.hello.HelloFactory',
17+
'nextflow.hello.HelloExtension'
18+
]
19+
20+
publishing {
21+
github {
22+
repository = 'nextflow-io/nf-hello'
23+
userName = project.findProperty('github_username')
24+
authToken = project.findProperty('github_access_token')
25+
email = project.findProperty('github_commit_email')
26+
27+
indexUrl = 'https://github.com/nextflow-io/plugins/blob/main/plugins.json'
28+
}
29+
}
30+
}

buildSrc/build.gradle

Lines changed: 0 additions & 14 deletions
This file was deleted.

buildSrc/src/main/groovy/io.nextflow.groovy-application-conventions.gradle

Lines changed: 0 additions & 11 deletions
This file was deleted.

buildSrc/src/main/groovy/io.nextflow.groovy-common-conventions.gradle

Lines changed: 0 additions & 48 deletions
This file was deleted.

buildSrc/src/main/groovy/io.nextflow.groovy-library-conventions.gradle

Lines changed: 0 additions & 11 deletions
This file was deleted.

gradle/wrapper/gradle-wrapper.jar

4.41 KB
Binary file not shown.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
46
zipStoreBase=GRADLE_USER_HOME
57
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)