|
| 1 | +# Documentation for Developers |
| 2 | + |
| 3 | +This document describes how to set up and develop native-build-tools on your local machine. |
| 4 | + |
| 5 | +## Environment |
| 6 | + |
| 7 | +The project uses Gradle as its build system. At the very minimum, you should set `JAVA_HOME` to a [Gradle-compatible JDK](https://docs.gradle.org/current/userguide/compatibility.html). |
| 8 | + |
| 9 | +Some build tasks require a GraalVM JDK (e.g., tests). You should set `GRAALVM_HOME` to an appropriate GraalVM JDK. |
| 10 | + |
| 11 | +## IDE setup |
| 12 | + |
| 13 | +The native-build-tools repo is set up as a multi-project Gradle project, with the Maven and Gradle plugins declared as subprojects of the root project. |
| 14 | +To set the project up in your IDE (e.g., IntelliJ IDEA), import the root project and the IDE should automatically import the subprojects. |
| 15 | + |
| 16 | +## Building & testing |
| 17 | + |
| 18 | +You can use the various commands in the [Gradle build lifecycle](https://docs.gradle.org/current/userguide/build_lifecycle.html) to build and test the project. |
| 19 | +Some examples (all executed from the root of the repository): |
| 20 | + |
| 21 | +```bash |
| 22 | +# Build all projects |
| 23 | +./gradlew assemble |
| 24 | + |
| 25 | +# Build only the native-gradle-plugin (for example) |
| 26 | +./gradlew :native-gradle-plugin:assemble |
| 27 | + |
| 28 | +# Build and run all tests |
| 29 | +./gradlew build |
| 30 | +``` |
| 31 | + |
| 32 | + |
| 33 | +## Debugging plugin(s) |
| 34 | +It is often useful to attach a debugger to the Gradle and Maven plugins during a project build. |
| 35 | + |
| 36 | +For the Gradle plugin, this can be accomplished by passing debugger options to the Gradle daemon via `org.gradle.jvmargs`, for example: |
| 37 | + |
| 38 | +```bash |
| 39 | +JAVA_OPTS="-Dorg.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" ./gradlew assemble |
| 40 | +``` |
| 41 | + |
| 42 | +The Gradle daemon will suspend on start-up, wait for you to attach a debugger, and then remain attached for subsequent Gradle commands. |
| 43 | + |
| 44 | +For the Maven plugin, simply use the `mvnDebug` command in place of the `mvn` command. |
| 45 | + |
| 46 | +## Testing local changes with an existing project |
| 47 | +A common development task is to modify a plugin and then test it with an existing project. |
| 48 | + |
| 49 | +To do this, first modify the project as necessary, and then build and publish the plugins to the local Maven repository: |
| 50 | +```bash |
| 51 | +./gradlew publishToMavenLocal --no-parallel |
| 52 | +``` |
| 53 | + |
| 54 | +Next, update the plugin version string in the project build files. |
| 55 | +The version can be found manually by searching for the published artifacts in `~/.m2/repository/org/graalvm/buildtools/native/`, or alternatively by checking the `nativeBuildTools` property [here](gradle/libs.versions.toml). |
| 56 | + |
| 57 | +For Gradle, the change looks like the following. |
| 58 | +You may also need to direct Gradle to use the local Maven repository to resolve the plugin: |
| 59 | +```bash |
| 60 | +# build.gradle |
| 61 | + plugins { |
| 62 | + ... |
| 63 | +- id 'org.graalvm.buildtools.native' version '0.9.25' |
| 64 | ++ id 'org.graalvm.buildtools.native' version '0.10.5-SNAPSHOT' |
| 65 | + } |
| 66 | + |
| 67 | + repositories { |
| 68 | ++ mavenLocal() |
| 69 | + ... |
| 70 | + } |
| 71 | + |
| 72 | +# settings.gradle |
| 73 | +pluginManagement { |
| 74 | + repositories { |
| 75 | ++ mavenLocal() |
| 76 | + ... |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +For Maven, simply bump the version and it should try the local repository automatically: |
| 82 | +```bash |
| 83 | +# pom.xml |
| 84 | +- <native.maven.plugin.version>0.9.25</native.maven.plugin.version> |
| 85 | ++ <native.maven.plugin.version>0.10.5-SNAPSHOT</native.maven.plugin.version> |
| 86 | +``` |
| 87 | + |
| 88 | +Then, run your build as usual. Gradle should find the plugin in the local repository and use it for the build. |
| 89 | + |
| 90 | + |
| 91 | + |
0 commit comments