-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #
- Loading branch information
Showing
12 changed files
with
280 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/gradle/src/migrations/20-2-0/add-include-subprojects-tasks.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
packages/gradle/src/migrations/20-2-0/add-include-subprojects-tasks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Oops, something went wrong.