Skip to content
Cédric Champeau edited this page Nov 20, 2024 · 3 revisions

Using dependent Micronaut projects from source

Since release 7.3.0 of the build plugins, it is now possible to use Micronaut dependencies from source during development. The dependencies will be automatically cloned from their GitHub repository and used in the build, whether it's a local build or a build on CI. This is basically a better replacement for snapshot dependencies: instead of having to publish a snapshot of a module in order to test changes, you can now simply point to the branch which contains the changes.

Requirements

  • Micronaut Build Plugins 7.3.0
  • that the included build has standardizedProjectNames set to true (for Micronaut Core, this is only true since the 4.8.x branch)

Usage

In your settings.gradle(.kts) file, in the micronautBuild section, add requiresDevelopmentVersion as needed, for example:

micronautBuild {
    useStandardizedProjectNames = true

    importMicronautCatalog()
    importMicronautCatalog("micronaut-serde")
    importMicronautCatalog("micronaut-sql")
    importMicronautCatalog("micronaut-test-resources")

    requiresDevelopmentVersion("micronaut-core", "4.8.x")
    requiresDevelopmentVersion("micronaut-sql", "6.0.x")
}

This will trigger the substitution of dependencies from the versions declared in the gradle/libs.versions.toml to their sources. In this case, micronaut-core will be fetched and will use branch 4.8.x, while micronaut-sql will use branch 6.0.x. Again, there's no need to publish the dependencies to maven local, or to a remote repository, to test changes!

Using local clones instead of remote branches

By default, this feature will trigger the creation of a checkouts directory where the included projects will be cloned. However, it may be more practical, for local development, to use local clones. In this case, the branch name declared in the settings.gradle(.kts) file will simply be ignored.

In order to do this, add the auto.include.git.dirs property to your ~/.gradle/gradle.properties file, and point it to a directory where your Micronaut projects are cloned (it's the easiest if they are siblings in a single directory).

For example:

auto.include.git.dirs=/home/cchampeau/DEV/PROJECTS/GITHUB/micronaut

The directory names should match the repository names (in the example above, micronaut-core and micronaut-sql).

How to resolve a dependency published to Maven Local

You may have to modify settings.gradle and add:

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        mavenLocal {
            mavenContent {
                snapshotsOnly()
            }
        }
    }
}

and in the base script of the module e.g. buildSrc/src/main/groovy/io.micronaut.build.internal.aws-base.gradle

repositories {
    mavenCentral()
    mavenLocal() {
        mavenContent {
            snapshotsOnly()
        }
    }
}