Skip to content

Commit

Permalink
feat(nx-spring-boot): merge buildJar and buildWar executors
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `build` is now the only executor to use to build the final jar or war

Closes #43
tinesoft committed Jan 7, 2022
1 parent 131df91 commit 9fdfec2
Showing 12 changed files with 41 additions and 146 deletions.
5 changes: 1 addition & 4 deletions packages/nx-spring-boot/README.md
Original file line number Diff line number Diff line change
@@ -108,13 +108,10 @@ Here the list of available executors:
| `run` \| `serve`<sup>*</sup>| `ignoreWrapper:boolean`, `args: string[]` | Runs the project using either `./mvnw\|mvn spring-boot:run` or `./gradlew\|gradle bootRun` |
| `test` | `ignoreWrapper:boolean`, `args: string[]` | Tests the project using either `./mvnw\|mvn test` or `./gradlew\|gradle test` |
| `clean` | `ignoreWrapper:boolean`, `args: string[]` | Cleans the project using either `./mvnw\|mvn clean` or `./gradlew\|gradle clean` |
| `buidlJar`<sup>*</sup> | `ignoreWrapper:boolean`, `args: string[]` | Packages the project into an executable Jar using either `./mvnw\|mvn spring-boot:repackage` or `./gradlew\|gradle bootJar` |
| `buildWar`<sup>*</sup> | `ignoreWrapper:boolean`, `args: string[]` | Packages the project into an executable War using either `./mvnw\|mvn spring-boot:repackage` or `./gradlew\|gradle bootWar` |
| `build` | `ignoreWrapper:boolean`, `args: string[]` | Packages the project into an executable Jar using either `./mvnw\|mvn package` or `./gradlew\|gradle build` |
| `buildInfo`<sup>*</sup> | `ignoreWrapper:boolean`, | Generates a `build-info.properties` using either `./mvnw\|mvn spring-boot:build-info` or `./gradlew\|gradle bootBuildInfo` |
| `buildImage`<sup>*</sup> | `ignoreWrapper:boolean`, `args: string[]` | Generates an [OCI Image](https://github.com/opencontainers/image-spec) using either `./mvnw\|mvn spring-boot:build-image` or `./gradlew\|gradle bootBuildImage` |

> <sup>*</sup> = These executors are only available if the project is a Spring Boot `application`.
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).
25 changes: 10 additions & 15 deletions packages/nx-spring-boot/executors.json
Original file line number Diff line number Diff line change
@@ -3,42 +3,37 @@
"run": {
"implementation": "./src/executors/run/executor",
"schema": "./src/executors/run/schema.json",
"description": "Executor to run the application"
"description": "Executor to run the project"
},
"serve": {
"implementation": "./src/executors/run/executor",
"schema": "./src/executors/serve/schema.json",
"description": "Executor to serve the application (alias to 'run' executor)"
"description": "Executor to serve the project (alias to 'run' executor)"
},
"test": {
"implementation": "./src/executors/test/executor",
"schema": "./src/executors/test/schema.json",
"description": "Executor to test the application"
"description": "Executor to test the project"
},
"clean": {
"implementation": "./src/executors/clean/executor",
"schema": "./src/executors/clean/schema.json",
"description": "Executor to clean the application"
"description": "Executor to clean the project"
},
"buildJar": {
"implementation": "./src/executors/build-jar/executor",
"schema": "./src/executors/build-jar/schema.json",
"description": "Executor to build the application's executable Jar"
},
"buildWar": {
"implementation": "./src/executors/build-war/executor",
"schema": "./src/executors/build-war/schema.json",
"description": "Executor to build the application's executable War"
"build": {
"implementation": "./src/executors/build/executor",
"schema": "./src/executors/build/schema.json",
"description": "Executor to build the project's Jar or War"
},
"buildImage": {
"implementation": "./src/executors/build-image/executor",
"schema": "./src/executors/build-image/schema.json",
"description": "Executor to build the application's OCI image"
"description": "Executor to build the project's OCI image"
},
"buildInfo": {
"implementation": "./src/executors/build-info/executor",
"schema": "./src/executors/build-info/schema.json",
"description": "Executor to build the application's build information"
"description": "Executor to build the project's build information"
}
}
}
6 changes: 2 additions & 4 deletions packages/nx-spring-boot/src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@ export const GRADLE_BOOT_COMMAND_MAPPER : BuilderCommandAliasMapper = {
'run': 'bootRun',
'test': 'test',
'clean': 'clean',
'buildJar': 'bootJar',
'buildWar': 'bootWar',
'build': 'build',
'buildImage': 'bootBuildImage',
'buildInfo': 'bootBuildInfo'
}
@@ -16,8 +15,7 @@ export const MAVEN_BOOT_COMMAND_MAPPER: BuilderCommandAliasMapper = {
'run': 'spring-boot:run',
'test': 'test',
'clean': 'clean',
'buildJar': 'spring-boot:repackage',
'buildWar': 'spring-boot:repackage',
'build': 'package',
'buildImage': 'spring-boot:build-image',
'buildInfo': 'spring-boot:build-info'
}
17 changes: 0 additions & 17 deletions packages/nx-spring-boot/src/executors/build-jar/executor.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/nx-spring-boot/src/executors/build-jar/schema.d.ts

This file was deleted.

24 changes: 0 additions & 24 deletions packages/nx-spring-boot/src/executors/build-jar/schema.json

This file was deleted.

48 changes: 0 additions & 48 deletions packages/nx-spring-boot/src/executors/build-war/executor.spec.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/nx-spring-boot/src/executors/build-war/executor.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { logger } from '@nrwl/devkit';
import { mocked } from 'ts-jest/utils';

import { buildJarExecutor } from './executor';
import { BuildJarExecutorOptions } from './schema';
import { buildExecutor } from './executor';
import { BuildExecutorOptions } from './schema';
import { GRADLE_WRAPPER_EXECUTABLE, MAVEN_WRAPPER_EXECUTABLE, NX_SPRING_BOOT_PKG } from '@nxrocks/common';
import { expectExecutorCommandRanWith, mockExecutorContext } from '@nxrocks/common/testing';

@@ -15,11 +15,11 @@ import * as fsUtility from '@nrwl/workspace/src/utils/fileutils';
import * as cp from 'child_process';

const mockContext = mockExecutorContext(NX_SPRING_BOOT_PKG, 'build-jar');
const options: BuildJarExecutorOptions = {
const options: BuildExecutorOptions = {
root: 'apps/bootapp'
};

describe('BuildJar Executor', () => {
describe('Build Executor', () => {

beforeEach(async () => {
jest.spyOn(logger, 'info');
@@ -32,14 +32,14 @@ describe('BuildJar Executor', () => {

it.each`
ignoreWrapper | buildSystem | buildFile | execute
${true} | ${'maven'} | ${'pom.xml'} | ${'mvn spring-boot:repackage '}
${true} | ${'gradle'} | ${'build.gradle'} | ${'gradle bootJar '}
${false} | ${'maven'} | ${'pom.xml'} | ${MAVEN_WRAPPER_EXECUTABLE + ' spring-boot:repackage '}
${false} | ${'gradle'} | ${'build.gradle'} | ${GRADLE_WRAPPER_EXECUTABLE + ' bootJar '}
${true} | ${'maven'} | ${'pom.xml'} | ${'mvn package '}
${true} | ${'gradle'} | ${'build.gradle'} | ${'gradle build '}
${false} | ${'maven'} | ${'pom.xml'} | ${MAVEN_WRAPPER_EXECUTABLE + ' package '}
${false} | ${'gradle'} | ${'build.gradle'} | ${GRADLE_WRAPPER_EXECUTABLE + ' build '}
`('should execute a $buildSystem build and ignoring wrapper : $ignoreWrapper', async ({ ignoreWrapper, buildSystem, buildFile, execute }) => {
mocked(fsUtility.fileExists).mockImplementation((filePath: string) => filePath.indexOf(buildFile) !== -1);

await buildJarExecutor({ ...options, ignoreWrapper }, mockContext);
await buildExecutor({ ...options, ignoreWrapper }, mockContext);

expectExecutorCommandRanWith(execute, mockContext, options);
});
17 changes: 17 additions & 0 deletions packages/nx-spring-boot/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ExecutorContext } from '@nrwl/devkit'
import * as path from 'path'
import { BuildExecutorOptions } from './schema'
import { runBootPluginCommand } from '../../utils/boot-utils'

export async function buildExecutor(options: BuildExecutorOptions, context: ExecutorContext){
const root = path.resolve(context.root, options.root);
const result = runBootPluginCommand('build', options.args, { cwd : root, ignoreWrapper: options.ignoreWrapper});

if (!result.success) {
throw new Error();
}

return result;
}

export default buildExecutor;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export interface BuildWarExecutorOptions {
export interface BuildExecutorOptions {
root: string;
ignoreWrapper?: boolean;
args?: string[];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/schema",
"title": "Build War executor",
"title": "Build executor",
"description": "",
"cli": "nx",
"type": "object",

0 comments on commit 9fdfec2

Please sign in to comment.