fix(gradle): read tasks from properties report (#29124)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Some gradle tasks are not real tasks. They exist in `tasks.txt` because it is derived from subprojects should not be a real target for that project. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Gradle projects only have real gradle tasks which are not derived from their subproject tasks. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
7328a8dae4
commit
37adb48db8
@ -29,8 +29,7 @@ describe('Gradle', () => {
|
|||||||
expect(projects).toContain('utilities');
|
expect(projects).toContain('utilities');
|
||||||
expect(projects).toContain(gradleProjectName);
|
expect(projects).toContain(gradleProjectName);
|
||||||
|
|
||||||
let buildOutput = runCLI('build app', { verbose: true });
|
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 list:build');
|
||||||
expect(buildOutput).toContain(':list:classes');
|
expect(buildOutput).toContain(':list:classes');
|
||||||
expect(buildOutput).toContain('nx run utilities:build');
|
expect(buildOutput).toContain('nx run utilities:build');
|
||||||
@ -41,15 +40,6 @@ describe('Gradle', () => {
|
|||||||
`list/build/libs/list.jar`,
|
`list/build/libs/list.jar`,
|
||||||
`utilities/build/libs/utilities.jar`
|
`utilities/build/libs/utilities.jar`
|
||||||
);
|
);
|
||||||
|
|
||||||
buildOutput = runCLI(`build ${gradleProjectName}`, { verbose: true });
|
|
||||||
// root project depends on app, list and utilities
|
|
||||||
expect(buildOutput).toContain('nx run app:build');
|
|
||||||
expect(buildOutput).toContain(':app:classes');
|
|
||||||
expect(buildOutput).toContain('nx run list:build');
|
|
||||||
expect(buildOutput).toContain(':list:classes');
|
|
||||||
expect(buildOutput).toContain('nx run utilities:build');
|
|
||||||
expect(buildOutput).toContain(':utilities:classes');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should track dependencies for new app', () => {
|
it('should track dependencies for new app', () => {
|
||||||
|
|||||||
@ -44,8 +44,11 @@ export function TargetConfigurationGroupList({
|
|||||||
if (hasGroups) {
|
if (hasGroups) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{Object.entries(targetsGroup.groups).map(
|
{Object.entries(targetsGroup.groups)
|
||||||
([targetGroupName, targets]) => {
|
.sort(([targetGroupName1], [targetGroupName2]) =>
|
||||||
|
targetGroupName1.localeCompare(targetGroupName2)
|
||||||
|
)
|
||||||
|
.map(([targetGroupName, targets]) => {
|
||||||
return (
|
return (
|
||||||
<TargetConfigurationGroupContainer
|
<TargetConfigurationGroupContainer
|
||||||
targetGroupName={targetGroupName}
|
targetGroupName={targetGroupName}
|
||||||
@ -71,8 +74,7 @@ export function TargetConfigurationGroupList({
|
|||||||
</ul>
|
</ul>
|
||||||
</TargetConfigurationGroupContainer>
|
</TargetConfigurationGroupContainer>
|
||||||
);
|
);
|
||||||
}
|
})}
|
||||||
)}
|
|
||||||
<TargetConfigurationGroupContainer
|
<TargetConfigurationGroupContainer
|
||||||
targetGroupName="Others"
|
targetGroupName="Others"
|
||||||
targetsNumber={targetsGroup.targets.length}
|
targetsNumber={targetsGroup.targets.length}
|
||||||
|
|||||||
@ -11,6 +11,12 @@
|
|||||||
"cli": "nx",
|
"cli": "nx",
|
||||||
"description": "This function changes !{projectRoot}/test/**/* in nx.json for production to !{projectRoot}/src/test/**/*",
|
"description": "This function changes !{projectRoot}/test/**/* in nx.json for production to !{projectRoot}/src/test/**/*",
|
||||||
"factory": "./src/migrations/19-4-1/change-regex-test-production"
|
"factory": "./src/migrations/19-4-1/change-regex-test-production"
|
||||||
|
},
|
||||||
|
"add-include-subprojects-tasks": {
|
||||||
|
"version": "20.2.0-beta.4",
|
||||||
|
"cli": "nx",
|
||||||
|
"description": "Add includeSubprojectsTasks to build.gradle file",
|
||||||
|
"factory": "./src/migrations/20-2-0/add-include-subprojects-tasks"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packageJsonUpdates": {}
|
"packageJsonUpdates": {}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ jobs:
|
|||||||
main-branch-name: 'main'
|
main-branch-name: 'main'
|
||||||
|
|
||||||
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
||||||
- run: ./nx affected --base=$NX_BASE --head=$NX_HEAD -t test build
|
- run: ./nx affected --base=$NX_BASE --head=$NX_HEAD -t build
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
@ -78,7 +78,7 @@ jobs:
|
|||||||
- uses: nrwl/nx-set-shas@v4
|
- uses: nrwl/nx-set-shas@v4
|
||||||
|
|
||||||
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
||||||
- run: ./nx affected -t test build
|
- run: ./nx affected -t build
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ jobs:
|
|||||||
main-branch-name: 'main'
|
main-branch-name: 'main'
|
||||||
|
|
||||||
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
||||||
- run: ./nx affected --base=$NX_BASE --head=$NX_HEAD -t test build
|
- run: ./nx affected --base=$NX_BASE --head=$NX_HEAD -t build
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
@ -160,6 +160,6 @@ jobs:
|
|||||||
- uses: nrwl/nx-set-shas@v4
|
- uses: nrwl/nx-set-shas@v4
|
||||||
|
|
||||||
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
|
||||||
- run: ./nx affected -t test build
|
- run: ./nx affected -t build
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ function getCiCommands(ci: Schema['ci']): Command[] {
|
|||||||
comment: `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
|
comment: `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: `./nx affected --base=$NX_BASE --head=$NX_HEAD -t test build`,
|
command: `./nx affected --base=$NX_BASE --head=$NX_HEAD -t build`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ function getCiCommands(ci: Schema['ci']): Command[] {
|
|||||||
{
|
{
|
||||||
comment: `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
|
comment: `# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected`,
|
||||||
},
|
},
|
||||||
{ command: `./nx affected -t test build` },
|
{ command: `./nx affected -t build` },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ describe('@nx/gradle:init', () => {
|
|||||||
"options": {
|
"options": {
|
||||||
"buildTargetName": "build",
|
"buildTargetName": "build",
|
||||||
"classesTargetName": "classes",
|
"classesTargetName": "classes",
|
||||||
|
"includeSubprojectsTasks": false,
|
||||||
"testTargetName": "test",
|
"testTargetName": "test",
|
||||||
},
|
},
|
||||||
"plugin": "@nx/gradle",
|
"plugin": "@nx/gradle",
|
||||||
@ -48,6 +49,7 @@ describe('@nx/gradle:init', () => {
|
|||||||
"options": {
|
"options": {
|
||||||
"buildTargetName": "build",
|
"buildTargetName": "build",
|
||||||
"classesTargetName": "classes",
|
"classesTargetName": "classes",
|
||||||
|
"includeSubprojectsTasks": false,
|
||||||
"testTargetName": "test",
|
"testTargetName": "test",
|
||||||
},
|
},
|
||||||
"plugin": "@nx/gradle",
|
"plugin": "@nx/gradle",
|
||||||
|
|||||||
@ -52,6 +52,7 @@ function addPlugin(tree: Tree) {
|
|||||||
testTargetName: 'test',
|
testTargetName: 'test',
|
||||||
classesTargetName: 'classes',
|
classesTargetName: 'classes',
|
||||||
buildTargetName: 'build',
|
buildTargetName: 'build',
|
||||||
|
includeSubprojectsTasks: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
updateNxJson(tree, nxJson);
|
updateNxJson(tree, nxJson);
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
import { Tree, readNxJson } from '@nx/devkit';
|
||||||
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||||
|
import update from './add-include-subprojects-tasks';
|
||||||
|
|
||||||
|
describe('AddIncludeSubprojectsTasks', () => {
|
||||||
|
let tree: Tree;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
tree = createTreeWithEmptyWorkspace();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not change nx.json if @nx/gradle is not added', async () => {
|
||||||
|
tree.write('nx.json', JSON.stringify({ namedInputs: {} }));
|
||||||
|
update(tree);
|
||||||
|
expect(readNxJson(tree)).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"namedInputs": {},
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add includeSubprojectsTasks to @nx/gradle plugin', async () => {
|
||||||
|
tree.write('nx.json', JSON.stringify({ plugins: ['@nx/gradle'] }));
|
||||||
|
update(tree);
|
||||||
|
expect(readNxJson(tree)).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"options": {
|
||||||
|
"includeSubprojectsTasks": true,
|
||||||
|
},
|
||||||
|
"plugin": "@nx/gradle",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add includeSubprojectsTasks to @nx/gradle plugin with options', async () => {
|
||||||
|
tree.write(
|
||||||
|
'nx.json',
|
||||||
|
JSON.stringify({
|
||||||
|
plugins: [
|
||||||
|
{ plugin: '@nx/gradle', options: { testTargetName: 'test' } },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
update(tree);
|
||||||
|
expect(readNxJson(tree)).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"options": {
|
||||||
|
"includeSubprojectsTasks": true,
|
||||||
|
"testTargetName": "test",
|
||||||
|
},
|
||||||
|
"plugin": "@nx/gradle",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
import { Tree, readNxJson, updateNxJson } from '@nx/devkit';
|
||||||
|
import { hasGradlePlugin } from '../../utils/has-gradle-plugin';
|
||||||
|
import { GradlePluginOptions } from '../../plugin/nodes';
|
||||||
|
|
||||||
|
// This function add options includeSubprojectsTasks as true in nx.json for gradle plugin
|
||||||
|
export default function update(tree: Tree) {
|
||||||
|
const nxJson = readNxJson(tree);
|
||||||
|
if (!nxJson) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!hasGradlePlugin(tree)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let gradlePluginIndex = nxJson.plugins.findIndex((p) =>
|
||||||
|
typeof p === 'string' ? p === '@nx/gradle' : p.plugin === '@nx/gradle'
|
||||||
|
);
|
||||||
|
let gradlePlugin = nxJson.plugins[gradlePluginIndex];
|
||||||
|
if (typeof gradlePlugin === 'string') {
|
||||||
|
gradlePlugin = {
|
||||||
|
plugin: '@nx/gradle',
|
||||||
|
options: {
|
||||||
|
includeSubprojectsTasks: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
nxJson.plugins[gradlePluginIndex] = gradlePlugin;
|
||||||
|
} else {
|
||||||
|
gradlePlugin.options ??= {};
|
||||||
|
(gradlePlugin.options as GradlePluginOptions).includeSubprojectsTasks =
|
||||||
|
true;
|
||||||
|
}
|
||||||
|
updateNxJson(tree, nxJson);
|
||||||
|
}
|
||||||
@ -30,8 +30,17 @@ describe('@nx/gradle/plugin', () => {
|
|||||||
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
||||||
['proj/build.gradle', new Map([['build', 'build']])],
|
['proj/build.gradle', new Map([['build', 'build']])],
|
||||||
]),
|
]),
|
||||||
|
gradleProjectToTasksMap: new Map<string, Set<string>>([
|
||||||
|
['proj', new Set(['test'])],
|
||||||
|
]),
|
||||||
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
||||||
['proj', new Map([['test', 'Verification']])],
|
[
|
||||||
|
'proj',
|
||||||
|
new Map([
|
||||||
|
['test', 'Verification'],
|
||||||
|
['build', 'Build'],
|
||||||
|
]),
|
||||||
|
],
|
||||||
]),
|
]),
|
||||||
gradleProjectToProjectName: new Map<string, string>([['proj', 'proj']]),
|
gradleProjectToProjectName: new Map<string, string>([['proj', 'proj']]),
|
||||||
gradleProjectNameToProjectRootMap: new Map<string, string>([
|
gradleProjectNameToProjectRootMap: new Map<string, string>([
|
||||||
@ -90,6 +99,7 @@ describe('@nx/gradle/plugin', () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
"name": "proj",
|
"name": "proj",
|
||||||
|
"projectType": "application",
|
||||||
"targets": {
|
"targets": {
|
||||||
"test": {
|
"test": {
|
||||||
"cache": true,
|
"cache": true,
|
||||||
@ -129,6 +139,111 @@ describe('@nx/gradle/plugin', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create nodes include subprojects tasks', async () => {
|
||||||
|
const results = await createNodesFunction(
|
||||||
|
['proj/build.gradle'],
|
||||||
|
{
|
||||||
|
buildTargetName: 'build',
|
||||||
|
includeSubprojectsTasks: true,
|
||||||
|
},
|
||||||
|
context
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(results).toMatchInlineSnapshot(`
|
||||||
|
[
|
||||||
|
[
|
||||||
|
"proj/build.gradle",
|
||||||
|
{
|
||||||
|
"projects": {
|
||||||
|
"proj": {
|
||||||
|
"metadata": {
|
||||||
|
"targetGroups": {
|
||||||
|
"Build": [
|
||||||
|
"build",
|
||||||
|
],
|
||||||
|
"Verification": [
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"technologies": [
|
||||||
|
"gradle",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"name": "proj",
|
||||||
|
"projectType": "application",
|
||||||
|
"targets": {
|
||||||
|
"build": {
|
||||||
|
"cache": true,
|
||||||
|
"command": "./gradlew proj:build",
|
||||||
|
"dependsOn": [
|
||||||
|
"^build",
|
||||||
|
"classes",
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
"production",
|
||||||
|
"^production",
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"help": {
|
||||||
|
"command": "./gradlew help --task proj:build",
|
||||||
|
"example": {
|
||||||
|
"options": {
|
||||||
|
"args": [
|
||||||
|
"--rerun",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"technologies": [
|
||||||
|
"gradle",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"cwd": ".",
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
"build",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"cache": true,
|
||||||
|
"command": "./gradlew proj:test",
|
||||||
|
"dependsOn": [
|
||||||
|
"testClasses",
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
"default",
|
||||||
|
"^production",
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"help": {
|
||||||
|
"command": "./gradlew help --task proj:test",
|
||||||
|
"example": {
|
||||||
|
"options": {
|
||||||
|
"args": [
|
||||||
|
"--rerun",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"technologies": [
|
||||||
|
"gradle",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"cwd": ".",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should create nodes based on gradle for nested project root', async () => {
|
it('should create nodes based on gradle for nested project root', async () => {
|
||||||
gradleReport = {
|
gradleReport = {
|
||||||
gradleFileToGradleProjectMap: new Map<string, string>([
|
gradleFileToGradleProjectMap: new Map<string, string>([
|
||||||
@ -138,6 +253,9 @@ describe('@nx/gradle/plugin', () => {
|
|||||||
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
||||||
['nested/nested/proj/build.gradle', new Map([['build', 'build']])],
|
['nested/nested/proj/build.gradle', new Map([['build', 'build']])],
|
||||||
]),
|
]),
|
||||||
|
gradleProjectToTasksMap: new Map<string, Set<string>>([
|
||||||
|
['proj', new Set(['test'])],
|
||||||
|
]),
|
||||||
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
||||||
['proj', new Map([['test', 'Verification']])],
|
['proj', new Map([['test', 'Verification']])],
|
||||||
]),
|
]),
|
||||||
@ -177,6 +295,7 @@ describe('@nx/gradle/plugin', () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
"name": "proj",
|
"name": "proj",
|
||||||
|
"projectType": "application",
|
||||||
"targets": {
|
"targets": {
|
||||||
"test": {
|
"test": {
|
||||||
"cache": true,
|
"cache": true,
|
||||||
@ -226,6 +345,9 @@ describe('@nx/gradle/plugin', () => {
|
|||||||
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
|
||||||
['nested/nested/proj/build.gradle', new Map([['build', 'build']])],
|
['nested/nested/proj/build.gradle', new Map([['build', 'build']])],
|
||||||
]),
|
]),
|
||||||
|
gradleProjectToTasksMap: new Map<string, Set<string>>([
|
||||||
|
['proj', new Set(['test'])],
|
||||||
|
]),
|
||||||
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
|
||||||
['proj', new Map([['test', 'Test']])],
|
['proj', new Map([['test', 'Test']])],
|
||||||
]),
|
]),
|
||||||
@ -290,6 +412,7 @@ describe('@nx/gradle/plugin', () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
"name": "proj",
|
"name": "proj",
|
||||||
|
"projectType": "application",
|
||||||
"targets": {
|
"targets": {
|
||||||
"test": {
|
"test": {
|
||||||
"cache": false,
|
"cache": false,
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import { getGradleExecFile, findGraldewFile } from '../utils/exec-gradle';
|
|||||||
|
|
||||||
const cacheableTaskType = new Set(['Build', 'Verification']);
|
const cacheableTaskType = new Set(['Build', 'Verification']);
|
||||||
const dependsOnMap = {
|
const dependsOnMap = {
|
||||||
build: ['^build', 'classes'],
|
build: ['^build', 'classes', 'test'],
|
||||||
testClasses: ['classes'],
|
testClasses: ['classes'],
|
||||||
test: ['testClasses'],
|
test: ['testClasses'],
|
||||||
classes: ['^classes'],
|
classes: ['^classes'],
|
||||||
@ -43,11 +43,12 @@ interface GradleTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface GradlePluginOptions {
|
export interface GradlePluginOptions {
|
||||||
|
includeSubprojectsTasks?: boolean; // default is false, show all gradle tasks in the project
|
||||||
ciTargetName?: string;
|
ciTargetName?: string;
|
||||||
testTargetName?: string;
|
testTargetName?: string;
|
||||||
classesTargetName?: string;
|
classesTargetName?: string;
|
||||||
buildTargetName?: string;
|
buildTargetName?: string;
|
||||||
[taskTargetName: string]: string | undefined;
|
[taskTargetName: string]: string | undefined | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeOptions(options: GradlePluginOptions): GradlePluginOptions {
|
function normalizeOptions(options: GradlePluginOptions): GradlePluginOptions {
|
||||||
@ -58,14 +59,7 @@ function normalizeOptions(options: GradlePluginOptions): GradlePluginOptions {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
type GradleTargets = Record<
|
type GradleTargets = Record<string, Partial<ProjectConfiguration>>;
|
||||||
string,
|
|
||||||
{
|
|
||||||
name: string;
|
|
||||||
targets: Record<string, TargetConfiguration>;
|
|
||||||
metadata: ProjectConfiguration['metadata'];
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
function readTargetsCache(cachePath: string): GradleTargets {
|
function readTargetsCache(cachePath: string): GradleTargets {
|
||||||
return existsSync(cachePath) ? readJsonFile(cachePath) : {};
|
return existsSync(cachePath) ? readJsonFile(cachePath) : {};
|
||||||
@ -180,6 +174,7 @@ async function createGradleProject(
|
|||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
gradleProjectToTasksTypeMap,
|
gradleProjectToTasksTypeMap,
|
||||||
|
gradleProjectToTasksMap,
|
||||||
gradleFileToOutputDirsMap,
|
gradleFileToOutputDirsMap,
|
||||||
gradleFileToGradleProjectMap,
|
gradleFileToGradleProjectMap,
|
||||||
gradleProjectToProjectName,
|
gradleProjectToProjectName,
|
||||||
@ -193,16 +188,26 @@ async function createGradleProject(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tasksTypeMap = gradleProjectToTasksTypeMap.get(gradleProject) as Map<
|
const tasksTypeMap: Map<string, string> = gradleProjectToTasksTypeMap.get(
|
||||||
string,
|
gradleProject
|
||||||
string
|
) as Map<string, string>;
|
||||||
>;
|
const tasksSet = gradleProjectToTasksMap.get(gradleProject) as Set<string>;
|
||||||
let tasks: GradleTask[] = [];
|
let tasks: GradleTask[] = [];
|
||||||
for (let [taskName, taskType] of tasksTypeMap.entries()) {
|
tasksSet.forEach((taskName) => {
|
||||||
tasks.push({
|
tasks.push({
|
||||||
type: taskType,
|
type: tasksTypeMap.get(taskName) as string,
|
||||||
name: taskName,
|
name: taskName,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
if (options.includeSubprojectsTasks) {
|
||||||
|
tasksTypeMap.forEach((taskType, taskName) => {
|
||||||
|
if (!tasksSet.has(taskName)) {
|
||||||
|
tasks.push({
|
||||||
|
type: taskType,
|
||||||
|
name: taskName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputDirs = gradleFileToOutputDirsMap.get(gradleFilePath) as Map<
|
const outputDirs = gradleFileToOutputDirsMap.get(gradleFilePath) as Map<
|
||||||
@ -219,8 +224,9 @@ async function createGradleProject(
|
|||||||
gradleFilePath,
|
gradleFilePath,
|
||||||
testFiles
|
testFiles
|
||||||
);
|
);
|
||||||
const project = {
|
const project: Partial<ProjectConfiguration> = {
|
||||||
name: projectName,
|
name: projectName,
|
||||||
|
projectType: 'application',
|
||||||
targets,
|
targets,
|
||||||
metadata: {
|
metadata: {
|
||||||
targetGroups,
|
targetGroups,
|
||||||
@ -266,7 +272,7 @@ async function createGradleTargets(
|
|||||||
getTestCiTargets(
|
getTestCiTargets(
|
||||||
testFiles,
|
testFiles,
|
||||||
gradleProject,
|
gradleProject,
|
||||||
targetName,
|
targetName as string,
|
||||||
options.ciTargetName,
|
options.ciTargetName,
|
||||||
inputsMap['test'],
|
inputsMap['test'],
|
||||||
outputs,
|
outputs,
|
||||||
@ -281,7 +287,7 @@ async function createGradleTargets(
|
|||||||
task.name
|
task.name
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
targets[targetName] = {
|
targets[targetName as string] = {
|
||||||
command: `${getGradleExecFile()} ${taskCommandToRun}`,
|
command: `${getGradleExecFile()} ${taskCommandToRun}`,
|
||||||
options: {
|
options: {
|
||||||
cwd: gradlewFileDirectory,
|
cwd: gradlewFileDirectory,
|
||||||
@ -303,10 +309,12 @@ async function createGradleTargets(
|
|||||||
...(outputs && outputs.length ? { outputs } : {}),
|
...(outputs && outputs.length ? { outputs } : {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!targetGroups[task.type]) {
|
if (task.type) {
|
||||||
targetGroups[task.type] = [];
|
if (!targetGroups[task.type]) {
|
||||||
|
targetGroups[task.type] = [];
|
||||||
|
}
|
||||||
|
targetGroups[task.type].push(targetName as string);
|
||||||
}
|
}
|
||||||
targetGroups[task.type].push(targetName);
|
|
||||||
}
|
}
|
||||||
return { targetGroups, targets };
|
return { targetGroups, targets };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ export interface GradleReport {
|
|||||||
buildFileToDepsMap: Map<string, string>;
|
buildFileToDepsMap: Map<string, string>;
|
||||||
gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
|
gradleFileToOutputDirsMap: Map<string, Map<string, string>>;
|
||||||
gradleProjectToTasksTypeMap: Map<string, Map<string, string>>;
|
gradleProjectToTasksTypeMap: Map<string, Map<string, string>>;
|
||||||
|
gradleProjectToTasksMap: Map<string, Set<String>>;
|
||||||
gradleProjectToProjectName: Map<string, string>;
|
gradleProjectToProjectName: Map<string, string>;
|
||||||
gradleProjectNameToProjectRootMap: Map<string, string>;
|
gradleProjectNameToProjectRootMap: Map<string, string>;
|
||||||
gradleProjectToChildProjects: Map<string, string[]>;
|
gradleProjectToChildProjects: Map<string, string[]>;
|
||||||
@ -105,6 +106,7 @@ export function processProjectReports(
|
|||||||
* Map of Gradle Build File to tasks type map
|
* Map of Gradle Build File to tasks type map
|
||||||
*/
|
*/
|
||||||
const gradleProjectToTasksTypeMap = new Map<string, Map<string, string>>();
|
const gradleProjectToTasksTypeMap = new Map<string, Map<string, string>>();
|
||||||
|
const gradleProjectToTasksMap = new Map<string, Set<String>>();
|
||||||
const gradleProjectToProjectName = new Map<string, string>();
|
const gradleProjectToProjectName = new Map<string, string>();
|
||||||
const gradleProjectNameToProjectRootMap = new Map<string, string>();
|
const gradleProjectNameToProjectRootMap = new Map<string, string>();
|
||||||
/**
|
/**
|
||||||
@ -159,6 +161,7 @@ export function processProjectReports(
|
|||||||
absBuildFilePath: string,
|
absBuildFilePath: string,
|
||||||
absBuildDirPath: string;
|
absBuildDirPath: string;
|
||||||
const outputDirMap = new Map<string, string>();
|
const outputDirMap = new Map<string, string>();
|
||||||
|
const tasks = new Set<string>();
|
||||||
for (const line of propertyReportLines) {
|
for (const line of propertyReportLines) {
|
||||||
if (line.startsWith('name: ')) {
|
if (line.startsWith('name: ')) {
|
||||||
projectName = line.substring('name: '.length);
|
projectName = line.substring('name: '.length);
|
||||||
@ -190,6 +193,10 @@ export function processProjectReports(
|
|||||||
`{workspaceRoot}/${relative(workspaceRoot, dirPath)}`
|
`{workspaceRoot}/${relative(workspaceRoot, dirPath)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (line.includes(': task ')) {
|
||||||
|
const [task] = line.split(': task ');
|
||||||
|
tasks.add(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!projectName || !absBuildFilePath || !absBuildDirPath) {
|
if (!projectName || !absBuildFilePath || !absBuildDirPath) {
|
||||||
@ -217,6 +224,7 @@ export function processProjectReports(
|
|||||||
gradleProject,
|
gradleProject,
|
||||||
dirname(buildFile)
|
dirname(buildFile)
|
||||||
);
|
);
|
||||||
|
gradleProjectToTasksMap.set(gradleProject, tasks);
|
||||||
}
|
}
|
||||||
if (line.endsWith('taskReport')) {
|
if (line.endsWith('taskReport')) {
|
||||||
const gradleProject = line.substring(
|
const gradleProject = line.substring(
|
||||||
@ -267,6 +275,7 @@ export function processProjectReports(
|
|||||||
buildFileToDepsMap,
|
buildFileToDepsMap,
|
||||||
gradleFileToOutputDirsMap,
|
gradleFileToOutputDirsMap,
|
||||||
gradleProjectToTasksTypeMap,
|
gradleProjectToTasksTypeMap,
|
||||||
|
gradleProjectToTasksMap,
|
||||||
gradleProjectToProjectName,
|
gradleProjectToProjectName,
|
||||||
gradleProjectNameToProjectRootMap,
|
gradleProjectNameToProjectRootMap,
|
||||||
gradleProjectToChildProjects,
|
gradleProjectToChildProjects,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user