npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nxrocks/nx-micronaut

v6.1.6

Published

Nx Plugin to generate, run, package, build (and more) Micronaut projects inside your Nx workspace

Downloads

279

Readme

nx-micronaut

npm version github action - release semantic-release

Nx Plugin to generate, run, package, build (and more) Micronaut projects inside your Nx workspace

Contents

Features

Here is a list of some of the coolest features of the plugin:

  • ✅ Generation of Micronaut applications based on Micronaut Launch API
  • ✅ Building, packaging, testing, etc your Micronaut projects
  • ✅ 🆕 Built-in support for creating multi-modules Micronaut projects with both Maven and Gradle
  • ✅ Built-in support for code formatting using the excellent Spotless plugin for Maven or Gradle
  • ✅ Built-in support for corporate proxies (either via --proxyUrl or by defining environment variable http_proxy, HTTP_PROXY, https_proxy or HTTPS_PROXY)
  • ✅ Integration with Nx's dependency graph (through nx graph or nx affected:graph): this allows you to visualize the dependencies of any Micronaut's Maven/Gradle applications or libraries inside your workspace, just like Nx natively does it for JS/TS-based projects!
  • ...

Setup

You can now use our own create-nx-micronaut CLI to easily create a Nx workspace, that comes with this plugin pre-installed!

Simply run:

# npm
npx create-nx-micronaut@latest
# or
# yarn
yarn create nx-micronaut

and you are good to go‧o‧o‧o! 🚀

More information here: create-nx-micronaut

Otherwise, this is the traditional way of setting things up:

1. Creating the Nx workspace

If you have not already, create an Nx workspace with the following:

# npm
npx create-nx-workspace@latest

# yarn
yarn create nx-workspace

2. Installing the Plugin

Then you need to install the plugin in order to generate Micronaut applications later on.

# npm
npm install @nxrocks/nx-micronaut --save-dev

# yarn
yarn add @nxrocks/nx-micronaut --dev

Generators

This plugin is composed of 2 main generators:

  • project generator
  • link generator

Generating Project (project generator)

Simply run the project generator with the following command:

nx g @nxrocks/nx-micronaut:project <your-app-name>

you can also use the following aliases to call the generator: proj, new, or create

You will be prompted for entering the most commonly customized generation options (like project's groupId, artifactId, packaging, dependencies, etc).

To skip the interactive prompt, or if you want to customize all non-prompted options, you can pass them along directly when running the command, as such:

nx g @nxrocks/nx-micronaut:project <your-app-name> --optionName1 optionValue1 ... --optionNameN optionValueN

Generation Options

Here the list of available generation options :

| Arguments | Description | | --------- | ------------------------- | | <name> | The name of your project. |

| Option | Value | Description | | --------------------------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | projectType | default | cli | function | grpc | messaging | Type of application to generate | | buildSystem | MAVEN | GRADLE | GRADLE_KOTLIN | Build system | | basePackage | string | Base package of the project | | javaVersion | JDK_8 | JDK_11 | JDK_17 | Java version to use | | language | JAVA | GROOVY | KOTLIN | Language to use | | testFramework | JUNIT | SPOCK | KOTEST | Test Framework to use | | skipFormat | boolean | Do not add the ability to format code (using Spotless plugin) | | features | string | List of features to use (comma-separated). Go to https://micronaut.io/launch to get the ids needed here | | transformIntoMultiModule | boolean | Transform the project into a multi-module project. Go to recipes for more information | | addToExistingParentModule | boolean | Add the project into an existing parent module project. Go to recipes for more information | | parentModuleName | string | Name of the parent module to create or to add child project into. Go to recipes for more information | | keepProjectLevelWrapper | boolean | Keep the Maven or Gradle wrapper files from child project (when generating a multi-module project). Go to recipes for more information | | micronautVersion | current | snapshot | previous | Micronaut version to use | | micronautLaunchUrl | https://launch.micronaut.io | URL to the Micronaut Launch instance to use | | proxyUrl | | The URL of the (corporate) proxy server to use to access Micronaut Launch | | tags | string | Tags to use for linting (comma-separated) | | directory | string | Directory where the project is placed |

Note: If you are working behind a corporate proxy, you can use the proxyUrl option to specify the URL of that corporate proxy server. Otherwise, you'll get a ETIMEDOUT error when trying to access official Micronaut Launch to generate the project. Even simpler, you can just define environment variable http_proxy, HTTP_PROXY, https_proxy or HTTPS_PROXY globally.

Linking Projects (link generator)

This generator is used to link a Micronaut project inside the workspace (the source project) with another project (the _target project), by adding the source project as an implicit dependency of the later.

Simply run the link generator with the following command:

nx g @nxrocks/nx-micronaut:link

you can also use the following aliases to call the generator: link-project

You will be prompted for entering the most commonly customized generation options (sourceProjectName, targetProjectName).

To skip the interactive prompt, you can pass options along directly when running the command, as such:

nx g @nxrocks/nx-micronaut:link --sourceProjectName <your-micronaut-app> --targetProjectName <your-other-app>

or even simpler:

nx g @nxrocks/nx-micronaut:link  <your-micronaut-app>  <your-other-app>

Generation Options

Here the list of available generation options :

| Arguments | Description | | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | <sourceProjectName> | The name of the source(Micronaut) project to link from. 1st argument of the link generator. Can also be provided as option --sourceProjectName | | <targetProjectName> | The name of the target project to link to. 2nd argument of the link generator. Can also be provided as option --targetProjectName |

Executors

Once your app is generated, you can now use executors to manage it.

Here the list of available executors:

| Executor | Arguments | Description | | ------------------------- | ------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | run | dev | serve | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Runs the project in dev mode using either ./mvnw\|mvn micronaut:dev or ./gradlew\|gradle micronautDev | | dockerfile | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Generates a Dockerfile depending on the packaging and micronaut.runtime properties using either ./mvnw\|mvn micronaut:dockerfile or ./gradlew\|gradle dockerfile | | build | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Packages the project using either ./mvnw\|mvn package or ./gradlew\|gradle build | | install | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Installs the project's artifacts to local Maven repository (in ~/.m2/repository) using either ./mvnw\|mvn install or ./gradlew\|gradle publishToMavenLocal | | test | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Tests the project using either ./mvnw\|mvn test or ./gradlew\|gradle test | | clean | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Cleans the project using either ./mvnw\|mvn clean or ./gradlew\|gradle clean | | format | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Format the project using Spotless plugin for Maven or Gradle | | aotConfigSample | ignoreWrapper:boolean, runFromParentModule:boolean, args: string[] | Generates a sample aot.properties using either ./mvnw\|mvn package or ./gradlew\|gradle package |

In order to execute the requested command, each executor will use, by default, the embedded ./mvnw or ./gradlew executable, that was generated alongside the project. If you want to rely on a globally installed mvn or gradle executable instead, add the --ignoreWrapper option to bypass it. This can be useful in a CI environment for example, or in a restricted environment where the binary cannot be downloaded (due to proxy/firewall limitations).

You can pass in additional arguments to the underlying Gradle or Maven, either temporarily (via --args="..."). For example:

nx run your-micronaut-app --args="-Dpackaging=docker-native"

Or, permanently by editing the related executor in the workspace.json file, as such:

{
  "version": 1,
  "projects": {
    "your-micronaut-app": {
      "projectType": "application",
      "root": "apps/your-micronaut-app",
      "sourceRoot": "apps/your-micronaut-app/src",
      "targets": {
        "dockerfile": {
          "executor": "@nxrocks/nx-micronaut:dockerfile",
          "options": {
            "root": "apps/your-micronaut-app",
            "args": ["-Dpackaging=docker-native"]// your additional args here
          }
        }
      }
    }},
  "cli": {
    "defaultCollection": "@nx/workspace"
  }
}

Running the project in dev mode - (run or dev or serve Executors)

nx run your-micronaut-app:run

// or
nx serve your-micronaut-app

Building the aplication - (build Executor)

nx build your-micronaut-app

Note: a task dependency to install executor of dependent (library) projects is added by the plugin, so that Nx will automatically install dependent artifacts to your local Maven repository, prior to running this command. This is particulaly useful, when for example, you have a Spring Boot application that depends on another Spring boot library in the workspace. No more need to install the library yourself first!

Install the project's artifacts to local Maven repository (in ~/.m2/repository) - (install Executor)

nx install your-micronaut-app

Generating the project dockerfile - (dockerfile Executor)

nx dockerfile your-micronaut-app"

Generating a sample AOT config file - (aot-sample-config Executor)

nx aot-sample-config your-micronaut-app"

Testing the project - (test Executor)

nx test your-micronaut-app

Cleaning the project - (clean Executor)

nx clean your-micronaut-app

Formatting the code - (format Executor)

nx run your-micronaut-app:format

// or simply

nx apply-format your-micronaut-app

Note: You *cannot** use the shorter nx format your-boot-app syntax here, because that would conflict with the native format command from Nx CLI.

Compatibility with Nx

Every Nx plugin relies on the underlying Nx Workspace/DevKit it runs on. This table provides the compatibility matrix between major versions of Nx workspace and this plugin.

| Plugin Version | Nx Workspace version | | -------------- | -------------------- | | >=v6.x.x | >=v18.x.x | | >=v5.x.x | >=v17.x.x | | >=v4.x.x | >=v16.x.x | | >=v3.x.x | >=v15.8.x | | >=v2.x.x | >=v15.x.x | | >=v1.x.x | >=v13.8.x |

License

Copyright (c) 2022-present Tine Kondo. Licensed under the MIT License (MIT)