fix(gradle): fix gradle tests (#30879)

<!-- 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 -->
currently, because it requires to sign locally, so i thought run command
like
`:project-graph:publishToMavenLocal -x
:project-graph:signNxProjectGraphPluginPluginMarkerMavenPublication -x
:project-graph:signPluginMavenPublication -x
:project-graph:publishNxProjectGraphPluginPluginMarkerMavenPublicationToMavenLocal
-x :project-graph:publishPluginMavenPublicationToMavenLocal` would
publish the plugin locally, but it actually does not. it does not throw
an error, but does not do anything at all.
so for e2e tests, it is actually pulling the latest published gradle
plugin from maven rather than test local code, hence the e2e errors.

also, currently project graph build for java version 21, we change it to
java 17 to be used by ocean repo.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
change the command to `./gradlew :project-graph:publishToMavenLocal
-PskipSign=true` and not apply signing when skip sign is true, so this
should be able to publish plugin to local repository.

work with java 17

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Emily Xiong 2025-05-08 17:29:10 -04:00 committed by GitHub
parent 468ec023c5
commit f339a1ab40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 68 additions and 58 deletions

View File

@ -16,7 +16,7 @@ import { join } from 'path';
import { createGradleProject } from './utils/create-gradle-project'; import { createGradleProject } from './utils/create-gradle-project';
import { createFileSync } from 'fs-extra'; import { createFileSync } from 'fs-extra';
xdescribe('Nx Import Gradle', () => { describe('Nx Import Gradle', () => {
const tempImportE2ERoot = join(e2eCwd, 'nx-import'); const tempImportE2ERoot = join(e2eCwd, 'nx-import');
beforeAll(() => { beforeAll(() => {
newProject({ newProject({
@ -72,6 +72,7 @@ xdescribe('Nx Import Gradle', () => {
const source = '.'; const source = '.';
const directory = 'projects/gradle-app-kotlin'; const directory = 'projects/gradle-app-kotlin';
try {
runCLI( runCLI(
`import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`, `import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`,
{ {
@ -94,9 +95,11 @@ xdescribe('Nx Import Gradle', () => {
runCLI(`show projects`); runCLI(`show projects`);
runCLI('build kotlin-app'); runCLI('build kotlin-app');
}).not.toThrow(); }).not.toThrow();
} finally {
// Cleanup
runCommand(`git add .`); runCommand(`git add .`);
runCommand(`git commit -am 'import kotlin project'`); runCommand(`git commit -am 'import kotlin project'`);
}
}); });
it('should be able to import a groovy gradle app', () => { it('should be able to import a groovy gradle app', () => {
@ -123,6 +126,7 @@ xdescribe('Nx Import Gradle', () => {
const source = '.'; const source = '.';
const directory = 'projects/gradle-app-groovy'; const directory = 'projects/gradle-app-groovy';
try {
runCLI( runCLI(
`import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`, `import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`,
{ {
@ -147,9 +151,11 @@ xdescribe('Nx Import Gradle', () => {
runCLI(`show projects`); runCLI(`show projects`);
runCLI('build groovy-app'); runCLI('build groovy-app');
}).not.toThrow(); }).not.toThrow();
} finally {
// Cleanup
runCommand(`git add .`); runCommand(`git add .`);
runCommand(`git commit -am 'import groovy project'`); runCommand(`git commit -am 'import groovy project'`);
}
}); });
}); });

View File

@ -45,7 +45,7 @@ describe('Gradle', () => {
expect(buildOutput).toContain(':utilities:classes'); expect(buildOutput).toContain(':utilities:classes');
}); });
xit('should track dependencies for new app', () => { it('should track dependencies for new app', () => {
if (type === 'groovy') { if (type === 'groovy') {
createFile( createFile(
`app2/build.gradle`, `app2/build.gradle`,

View File

@ -80,7 +80,7 @@ export function createGradleProject(
e2eConsoleLogger( e2eConsoleLogger(
execSync( execSync(
`${gradleCommand} :project-graph:publishToMavenLocal -x :project-graph:signNxProjectGraphPluginPluginMarkerMavenPublication -x :project-graph:signPluginMavenPublication -x :project-graph:publishNxProjectGraphPluginPluginMarkerMavenPublicationToMavenLocal -x :project-graph:publishPluginMavenPublicationToMavenLocal`, `${gradleCommand} :project-graph:publishToMavenLocal -PskipSign=true`,
{ {
cwd: `${__dirname}/../../../..`, cwd: `${__dirname}/../../../..`,
} }

View File

@ -108,15 +108,19 @@ afterEvaluate {
} }
} }
} }
}
val skipSign = project.findProperty("skipSign") == "true"
if (!skipSign) {
signing { signing {
afterEvaluate {
sign(publishing.publications["pluginMaven"]) sign(publishing.publications["pluginMaven"])
sign(publishing.publications["nxProjectGraphPluginPluginMarkerMaven"]) sign(publishing.publications["nxProjectGraphPluginPluginMarkerMaven"])
} }
} }
// Even if signing plugin was applied, we can prevent the sign tasks from running
tasks.withType<Sign>().configureEach { onlyIf { !skipSign } }
}
tasks.test { useJUnitPlatform() } tasks.test { useJUnitPlatform() }
java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) } java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) }