Skip to content

Commit 2d23b5a

Browse files
committed
add nx
1 parent 5a97d2e commit 2d23b5a

File tree

9 files changed

+2140
-0
lines changed

9 files changed

+2140
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ secrets.yml
4141
.sts4-cache
4242
.git-hooks/
4343
node_modules
44+
45+
.nx/installation
46+
.nx/cache
47+
.nx/workspace-data

.nx/nxw.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"use strict";
2+
// This file should be committed to your repository! It wraps Nx and ensures
3+
// that your local installation matches nx.json.
4+
// See: https://nx.dev/recipes/installation/install-non-javascript for more info.
5+
6+
7+
8+
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
const fs = require('fs');
11+
const path = require('path');
12+
const cp = require('child_process');
13+
const installationPath = path.join(__dirname, 'installation', 'package.json');
14+
function matchesCurrentNxInstall(currentInstallation, nxJsonInstallation) {
15+
if (!currentInstallation.devDependencies ||
16+
!Object.keys(currentInstallation.devDependencies).length) {
17+
return false;
18+
}
19+
try {
20+
if (currentInstallation.devDependencies['nx'] !==
21+
nxJsonInstallation.version ||
22+
require(path.join(path.dirname(installationPath), 'node_modules', 'nx', 'package.json')).version !== nxJsonInstallation.version) {
23+
return false;
24+
}
25+
for (const [plugin, desiredVersion] of Object.entries(nxJsonInstallation.plugins || {})) {
26+
if (currentInstallation.devDependencies[plugin] !== desiredVersion) {
27+
return false;
28+
}
29+
}
30+
return true;
31+
}
32+
catch {
33+
return false;
34+
}
35+
}
36+
function ensureDir(p) {
37+
if (!fs.existsSync(p)) {
38+
fs.mkdirSync(p, { recursive: true });
39+
}
40+
}
41+
function getCurrentInstallation() {
42+
try {
43+
return require(installationPath);
44+
}
45+
catch {
46+
return {
47+
name: 'nx-installation',
48+
version: '0.0.0',
49+
devDependencies: {},
50+
};
51+
}
52+
}
53+
function performInstallation(currentInstallation, nxJson) {
54+
fs.writeFileSync(installationPath, JSON.stringify({
55+
name: 'nx-installation',
56+
devDependencies: {
57+
nx: nxJson.installation.version,
58+
...nxJson.installation.plugins,
59+
},
60+
}));
61+
try {
62+
cp.execSync('npm i', {
63+
cwd: path.dirname(installationPath),
64+
stdio: 'inherit',
65+
windowsHide: false,
66+
});
67+
}
68+
catch (e) {
69+
// revert possible changes to the current installation
70+
fs.writeFileSync(installationPath, JSON.stringify(currentInstallation));
71+
// rethrow
72+
throw e;
73+
}
74+
}
75+
function ensureUpToDateInstallation() {
76+
const nxJsonPath = path.join(__dirname, '..', 'nx.json');
77+
let nxJson;
78+
try {
79+
nxJson = require(nxJsonPath);
80+
if (!nxJson.installation) {
81+
console.error('[NX]: The "installation" entry in the "nx.json" file is required when running the nx wrapper. See https://nx.dev/recipes/installation/install-non-javascript');
82+
process.exit(1);
83+
}
84+
}
85+
catch {
86+
console.error('[NX]: The "nx.json" file is required when running the nx wrapper. See https://nx.dev/recipes/installation/install-non-javascript');
87+
process.exit(1);
88+
}
89+
try {
90+
ensureDir(path.join(__dirname, 'installation'));
91+
const currentInstallation = getCurrentInstallation();
92+
if (!matchesCurrentNxInstall(currentInstallation, nxJson.installation)) {
93+
performInstallation(currentInstallation, nxJson);
94+
}
95+
}
96+
catch (e) {
97+
const messageLines = [
98+
'[NX]: Nx wrapper failed to synchronize installation.',
99+
];
100+
if (e instanceof Error) {
101+
messageLines.push('');
102+
messageLines.push(e.message);
103+
messageLines.push(e.stack);
104+
}
105+
else {
106+
messageLines.push(e.toString());
107+
}
108+
console.error(messageLines.join('\n'));
109+
process.exit(1);
110+
}
111+
}
112+
if (!process.env.NX_WRAPPER_SKIP_INSTALL) {
113+
ensureUpToDateInstallation();
114+
}
115+
116+
require('./installation/node_modules/nx/bin/nx');

build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
id "dev.nx.gradle.project-graph" version "+"
23
id "base"
34
id "org.jetbrains.kotlin.jvm" apply false // https://youtrack.jetbrains.com/issue/KT-30276
45
}
@@ -9,12 +10,18 @@ defaultTasks 'build'
910

1011
allprojects {
1112
group = "org.springframework.boot"
13+
apply {
14+
plugin("project-report")
15+
plugin("dev.nx.gradle.project-graph")
16+
}
1217
}
1318

1419
subprojects {
1520
apply plugin: "org.springframework.boot.conventions"
21+
// apply plugin: "dev.nx.gradle.project-graph"
1622

1723
repositories {
24+
mavenLocal()
1825
mavenCentral()
1926
spring.mavenRepositories()
2027
}
@@ -24,3 +31,14 @@ subprojects {
2431
}
2532
}
2633

34+
tasks.register("projectReportAll") {
35+
// All project reports of subprojects
36+
allprojects.forEach {
37+
dependsOn(it.tasks.getAt("projectReport"))
38+
}
39+
40+
// All projectReportAll of included builds
41+
gradle.includedBuilds.forEach {
42+
dependsOn(it.task(":projectReportAll"))
43+
}
44+
}

nx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
command -v node >/dev/null 2>&1 || { echo >&2 "Nx requires NodeJS to be available. To install NodeJS and NPM, see: https://nodejs.org/en/download/ ."; exit 1; }
3+
command -v npm >/dev/null 2>&1 || { echo >&2 "Nx requires npm to be available. To install NodeJS and NPM, see: https://nodejs.org/en/download/ ."; exit 1; }
4+
path_to_root=$(dirname $BASH_SOURCE)
5+
node $path_to_root/.nx/nxw.js $@

nx.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@ECHO OFF
2+
SETLOCAL
3+
SET path_to_root=%~dp0
4+
WHERE node >nul 2>nul
5+
IF %ERRORLEVEL% NEQ 0 (ECHO Nx requires NodeJS to be available. To install NodeJS and NPM, see: https://nodejs.org/en/download/ . & GOTO exit)
6+
WHERE npm >nul 2>nul
7+
IF %ERRORLEVEL% NEQ 0 (ECHO Nx requires npm to be available. To install NodeJS and NPM, see: https://nodejs.org/en/download/ . & GOTO exit)
8+
node %path_to_root%\.nx\nxw.js %*
9+
:exit
10+
cmd /c exit /b %ERRORLEVEL%

nx.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"installation": {
3+
"version": "0.0.0-pr-29464-f9a8c49",
4+
"plugins": {
5+
"@nx/gradle": "0.0.0-pr-29464-f9a8c49"
6+
}
7+
},
8+
"plugins": [
9+
{
10+
"plugin": "@nx/gradle",
11+
"options": {
12+
"testTargetName": "test",
13+
"classesTargetName": "classes",
14+
"buildTargetName": "build"
15+
}
16+
}
17+
],
18+
"namedInputs": {
19+
"default": [
20+
"{projectRoot}/**/*"
21+
],
22+
"production": [
23+
"default",
24+
"!{projectRoot}/src/test/**/*"
25+
]
26+
}
27+
}

0 commit comments

Comments
 (0)