Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add gradle plugin #21055

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ commands:
- ~/.pnpm-store
- ~/.cache/Cypress
- node_modules
install-sdkman:
description: Install SDKMAN
steps:
- restore_cache:
name: Restore SDKMAN executable and binaries from cache
keys:
- sdkman-cli-{{ arch }}-v2
- run:
name: Installing SDKMAN
command: |
if [ ! -d ~/.sdkman ]
then
curl -s "https://get.sdkman.io?rcupdate=false" | bash
sed -i -e 's/sdkman_auto_answer=false/sdkman_auto_answer=true/g' ~/.sdkman/etc/config
fi
echo -e '\nsource "/home/circleci/.sdkman/bin/sdkman-init.sh"' >> $BASH_ENV
source $BASH_ENV
sdk version
- save_cache:
name: Save SDKMAN executable and binaries to cache
key: sdkman-cli-{{ arch }}-v2
paths:
- ~/.sdkman
install-gradle:
description: Install gradle
parameters:
gradle-version:
type: string
default: ''
steps:
- restore_cache:
name: Restore Gradle binary from cache
keys:
- gradle-cli-{{ arch }}-v1
- run:
name: Installing Gradle
command: |
sdk install gradle << parameters.gradle-version >>
gradle --version
- save_cache:
name: Save Gradle binary to cache
key: gradle-cli-{{ arch }}-v1
paths:
- ~/.sdkman/candidates/gradle/
# -------------------------
# JOBS
# -------------------------
Expand Down Expand Up @@ -96,6 +140,9 @@ jobs:
sudo apt-get install -y ca-certificates lsof
- browser-tools/install-chrome
- browser-tools/install-chromedriver
- install-sdkman
- install-gradle:
gradle-version: '8.5'
- run-pnpm-install:
os: linux
- run:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/e2e-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ jobs:
codeowners: 'S04SJ6HHP0X'
- project: e2e-expo
codeowners: 'S04TNCNJG5N'
- project: e2e-gradle
codeowners: 'S04TNCNJG5N'
- project: e2e-jest
codeowners: 'S04T16BTJJY'
- project: e2e-js
Expand Down Expand Up @@ -242,6 +244,8 @@ jobs:
project: e2e-esbuild
- node_version: 18
project: e2e-expo
- node_version: 18
project: e2e-gradle
- node_version: 18
project: e2e-jest
- node_version: 18
Expand Down
20 changes: 20 additions & 0 deletions .nx/workflows/agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ launch-templates:
node_modules
~/.cache/Cypress
~/.pnpm-store
~/.sdkman
~/.sdkman/candidates/gradle
BASE_BRANCH: 'master'
- name: Install e2e deps
script: |
Expand Down Expand Up @@ -49,3 +51,21 @@ launch-templates:

- name: Load Cargo Env
script: echo "PATH=$HOME/.cargo/bin:$PATH" >> $NX_CLOUD_ENV

- name: Install zip and unzip
script: sudo apt-get -yqq install zip unzip

- name: Install SDKMAN and gradle
script: |
if [ ! -d $HOME/.sdkman ]
then
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
fi
sdk version
if [ ! -d $HOME/.sdkman/candidates/gradle/8.5 ]
then
sdk install gradle 8.5
fi
gradle --version
echo "PATH=$HOME/.sdkman/candidates/gradle/8.5/bin:$PATH" >> $NX_CLOUD_ENV
4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ rust-toolchain @nrwl/nx-native-reviewers
/packages/devkit/public-api.ts @FrozenPandaz @vsavkin
/packages/devkit/nx.ts @FrozenPandaz @vsavkin

# Gradle
/packages/gradle/** @FrozenPandaz @xiongemi
/e2e/gradle/** @FrozenPandaz @xiongemi

# Nx-Plugin
/docs/generated/packages/plugin/** @nrwl/nx-devkit-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/plugin/** @nrwl/nx-devkit-reviewers @nrwl/nx-docs-reviewers
Expand Down
14 changes: 14 additions & 0 deletions e2e/gradle/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable */
export default {
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
maxWorkers: 1,
globals: {},
globalSetup: '../utils/global-setup.ts',
globalTeardown: '../utils/global-teardown.ts',
displayName: 'e2e-gradle',
testTimeout: 600000,
preset: '../../jest.preset.js',
};
10 changes: 10 additions & 0 deletions e2e/gradle/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "e2e-gradle",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/gradle",
"projectType": "application",
"targets": {
"e2e": {}
},
"implicitDependencies": ["eslint"]
}
87 changes: 87 additions & 0 deletions e2e/gradle/src/gradle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
checkFilesExist,
cleanupProject,
createFile,
e2eConsoleLogger,
newProject,
runCLI,
runCommand,
uniq,
updateFile,
updateJson,
} from '@nx/e2e/utils';
import { execSync } from 'child_process';

describe('Gradle', () => {
let gradleProjectName = uniq('my-gradle-project');

beforeAll(() => {
newProject();
createGradleProject(gradleProjectName);
});
afterAll(() => cleanupProject());

it('should build', () => {
const projects = runCLI(`show projects`);
expect(projects).toContain('app');
expect(projects).toContain('list');
expect(projects).toContain('utilities');
expect(projects).toContain(gradleProjectName);

const buildOutput = runCLI('build app', { verbose: true });
// app depends on list and utilities
expect(buildOutput).toContain('nx run list:build');
expect(buildOutput).toContain('nx run utilities:build');

checkFilesExist(
`app/build/libs/app.jar`,
`list/build/libs/list.jar`,
`utilities/build/libs/utilities.jar`
);
});

it('should track dependencies for new app', () => {
createFile(
'app2/build.gradle.kts',
`
plugins {
id("gradleProject.kotlin-application-conventions")
}

dependencies {
implementation(project(":app"))
}
`
);
updateFile(`settings.gradle.kts`, (content) => {
content += `\r\ninclude("app2")`;
return content;
});
const buildOutput = runCLI('build app2', { verbose: true });
// app2 depends on app
expect(buildOutput).toContain('nx run app:build');
});
});

function createGradleProject(projectName: string) {
e2eConsoleLogger(`Using java version: ${execSync('java --version')}`);
e2eConsoleLogger(`Using gradle version: ${execSync('gradle --version')}`);
e2eConsoleLogger(execSync(`gradle help --task :init`).toString());
e2eConsoleLogger(
runCommand(
`gradle init --type kotlin-application --dsl kotlin --project-name ${projectName} --package gradleProject --no-incubating --split-project`
)
);
updateJson('nx.json', (nxJson) => {
nxJson.plugins = ['@nx/gradle'];
return nxJson;
});
createFile(
'build.gradle.kts',
`allprojects {
apply {
plugin("project-report")
}
}`
);
}
13 changes: 13 additions & 0 deletions e2e/gradle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
20 changes: 20 additions & 0 deletions e2e/gradle/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"**/*.d.ts",
"jest.config.ts"
]
}
1 change: 1 addition & 0 deletions e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const nxPackages = [
`@nx/eslint-plugin`,
`@nx/express`,
`@nx/esbuild`,
`@nx/gradle`,
`@nx/jest`,
`@nx/js`,
`@nx/eslint`,
Expand Down
9 changes: 9 additions & 0 deletions nx-dev/nx-dev/public/images/icons/gradle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions nx-dev/ui-references/src/lib/icons-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const iconsMap: Record<string, string> = {
'eslint-plugin': '/images/icons/eslint.svg',
expo: '/images/icons/expo.svg',
express: '/images/icons/express.svg',
gradle: '/images/icons/gradle.svg',
jest: '/images/icons/jest.svg',
js: '/images/icons/javascript.svg',
eslint: '/images/icons/eslint.svg',
Expand Down
37 changes: 37 additions & 0 deletions packages/gradle/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"ignoredDependencies": ["nx"]
}
]
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/nx-plugin-checks": "error"
}
}
]
}
18 changes: 18 additions & 0 deletions packages/gradle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<p style="text-align: center;">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
</picture>
</p>

{{links}}

<hr>

# Nx: Smart Monorepos · Fast CI

Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.

This package is a [Gradle plugin for Nx](https://nx.dev/gradle/overview).

{{content}}
1 change: 1 addition & 0 deletions packages/gradle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './plugin';
10 changes: 10 additions & 0 deletions packages/gradle/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html', 'json'],
globals: {},
displayName: 'gradle',
preset: '../../jest.preset.js',
};
4 changes: 4 additions & 0 deletions packages/gradle/migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"generators": {},
"packageJsonUpdates": {}
}
Loading