Skip to content

Commit 6b1d4dd

Browse files
authored
Merge pull request #21 from petebankhead/kotlin
Use Kotlin & QuPath Gradle Plugin
2 parents 3f2ce42 + 65a8ab7 commit 6b1d4dd

File tree

12 files changed

+154
-252
lines changed

12 files changed

+154
-252
lines changed

.github/workflows/jpackage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919

2020
- uses: actions/checkout@v4
2121

22-
- name: Set up JDK 17 # TODO: check Java version
22+
- name: Set up JDK 21 # TODO: check Java version
2323
uses: actions/setup-java@v4
2424
with:
25-
java-version: '17'
25+
java-version: '21'
2626
distribution: 'temurin'
2727

2828
- name: Validate Gradle wrapper

README.md

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
This repo contains a template and instructions to help create a new extension for [QuPath](https://qupath.github.io).
44

5-
It already contains two minimal extensions, so the first task is to make sure that they work.
5+
It already contains two minimal extensions - one using Java, one using Groovy - so the first task is to make sure that they work.
66
Then, it's a matter of customizing the code to make it more useful.
77

8-
> There are two extensions to show that you can use either Java or Groovy.
8+
> **Update!**
9+
> For QuPath v0.6.0 this repo switched to use Kotlin DSL for Gradle build files -
10+
> and also to use the [QuPath Gradle Plugin](https://github.com/qupath/qupath-gradle-plugin).
11+
>
12+
> The outcome is that the build files are _much_ simpler.
13+
914

1015
## Build the extension
1116

@@ -33,39 +38,88 @@ QuPath.
3338
> If you don't do that, you'll need to drag *all* the extra dependences onto QuPath to install them as well.
3439
3540
36-
## Set up in an IDE (optional)
41+
## Configure the extension
3742
38-
During development, things are likely to be much easier if you work within an IDE.
43+
Edit `settings.gradle.kts` to specify which version of QuPath your extension should be compatible with, e.g.
3944
40-
QuPath itself is developed using IntelliJ, and you can import the extension template there.
45+
```kotlin
46+
qupath {
47+
version = "0.6.0-SNAPSHOT"
48+
}
49+
```
50+
51+
Edit `build.gradle.kts` to specify the details of your extension
4152

42-
However, for development and testing, it can help to import QuPath *and* the extension and have them in your IDE side-by-side.
53+
```kotlin
54+
qupathExtension {
55+
name = "qupath-extension-template"
56+
group = "io.github.qupath"
57+
version = "0.1.0-SNAPSHOT"
58+
description = "A simple QuPath extension"
59+
automaticModule = "io.github.qupath.extension.template"
60+
}
61+
```
4362

44-
In IntelliJ, you can do this in a few steps:
45-
* Get QuPath's source code, as described at https://qupath.readthedocs.io/en/stable/docs/reference/building.html
46-
* Store your extension code in a directory *beside* QuPath's code. So it should be located next to the `qupath` code directory.
47-
* Import QuPath into IntelliJ as a Gradle project (you don't need to import the extension yet!)
48-
* See https://www.jetbrains.com/help/idea/work-with-gradle-projects.html
49-
* Within `qupath/settings.gradle` add the line `includeFlat 'your-extension-code-directory'` (updating the code directory as needed)
50-
* Refresh the Gradle project in IntelliJ, and your extension code should appear
51-
* Create a [Run configuration](https://www.jetbrains.com/help/idea/run-debug-configuration.html) in IntelliJ to launch QuPath. An example of how that looks is shown below:
5263

53-
<img src="qupath-intellij.png" alt="QuPath run configuration in IntelliJ" width="428" />
64+
## Run QuPath + the extension
5465

55-
Now when you run QuPath from IntelliJ, your extension should (hopefully) be found - there's no need to add it by drag & drop.
66+
During development, your probably want to run QuPath easily with your extension installed for debugging.
5667

57-
## Customize the extension
68+
### 0. Make sure you have Java installed
69+
You'll need to install Java first.
5870

59-
There are a few fixed steps to customizing the extension, and then the main creative part where you add your own code.
71+
At the time of writing, we use a Java 21 JDK downloaded from https://adoptium.net/
6072

61-
### Update `settings.gradle`
73+
> Java 21 is a 'Long Term Support' release - which is why we use it instead of the very latest version.
74+
75+
### 1. Get QuPath's source code
76+
You can find instructions at https://qupath.readthedocs.io/en/stable/docs/reference/building.html
77+
78+
### 2. Create an `include-extra` file
79+
Create a file called `include-extra` in the root directory of the QuPath source code (*not* the extension code!).
80+
81+
Set the contents of this file to:
82+
```
83+
[includeBuild]
84+
/path/to/your/extension
85+
86+
[dependencies]
87+
extension-group:extension-name
88+
```
89+
replacing the default lines where needed.
90+
91+
For example, to build the extension with the names given above you'd use
92+
```
93+
[includeBuild]
94+
../qupath-extension-template
6295
63-
Open `settings.gradle` and check the comment lines flagged with `\\TODO`.
64-
These point you towards parts you may well need to change.
96+
[dependencies]
97+
io.github.qupath:qupath-extension-template
98+
```
99+
100+
### 3. Run QuPath
101+
Run QuPath from the command line using
102+
```
103+
gradlew run
104+
```
105+
If all goes well, QuPath should launch and you can check the *Extensions* mention to confirm the extension is installed.
106+
107+
108+
## Set up in an IDE (optional)
109+
110+
During development, things are likely to be much easier if you work within an IDE.
111+
112+
QuPath itself is developed using IntelliJ, and you can import the extension template there.
113+
114+
The setup process is as above, and you'll need a a [Run configuration](https://www.jetbrains.com/help/idea/run-debug-configuration.html)
115+
to call `gradlew run`.
116+
117+
118+
## Customize the extension
65119

66-
### Update `build.gradle`
120+
Now you're ready for the creative part.
67121

68-
Open `build.gradle` and follow a similar process to with `settings.gradle`, to update the bits flagged with `\\TODO`.
122+
You can develop the extension using either Java or Groovy - the template includes examples of both.
69123

70124
### Create the extension Java or Groovy file(s)
71125

build.gradle

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

build.gradle.kts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
plugins {
2+
// Support writing the extension in Groovy (remove this if you don't want to)
3+
groovy
4+
// To optionally create a shadow/fat jar that bundle up any non-core dependencies
5+
id("com.gradleup.shadow") version "8.3.5"
6+
// QuPath Gradle extension convention plugin
7+
id("qupath-conventions")
8+
}
9+
10+
// TODO: Configure your extension here (please change the defaults!)
11+
qupathExtension {
12+
name = "qupath-extension-template"
13+
group = "io.github.qupath"
14+
version = "0.1.0-SNAPSHOT"
15+
description = "A simple QuPath extension"
16+
automaticModule = "io.github.qupath.extension.template"
17+
}
18+
19+
// TODO: Define your dependencies here
20+
dependencies {
21+
22+
// Main dependencies for most QuPath extensions
23+
shadow(libs.bundles.qupath)
24+
shadow(libs.bundles.logging)
25+
shadow(libs.qupath.fxtras)
26+
27+
// If you aren't using Groovy, this can be removed
28+
shadow(libs.bundles.groovy)
29+
30+
// For testing
31+
testImplementation(libs.bundles.qupath)
32+
testImplementation(libs.junit)
33+
34+
}

gradle/wrapper/gradle-wrapper.jar

121 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -55,7 +57,7 @@
5557
# Darwin, MinGW, and NonStop.
5658
#
5759
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5961
# within the Gradle project.
6062
#
6163
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,8 @@ done
8486
# shellcheck disable=SC2034
8587
APP_BASE_NAME=${0##*/}
8688
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90+
' "$PWD" ) || exit
8891

8992
# Use the maximum available, or set MAX_FD != -1 to use that value.
9093
MAX_FD=maximum

0 commit comments

Comments
 (0)