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

[gradle] generate initial files for convention plugin usage #24551

Merged
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
2 changes: 2 additions & 0 deletions generators/git/templates/.gitignore.jhi.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ out/
######################
.gradle/
/build/
/buildSrc/.gradle/
/buildSrc/build/

######################
# Package Files
Expand Down
6 changes: 6 additions & 0 deletions generators/gradle/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ exports[`generator - gradle with empty configuration should generate only gradle
".yo-rc.json": {
"stateCleared": "modified",
},
"buildSrc/build.gradle": {
"stateCleared": "modified",
},
"gradle/wrapper/gradle-wrapper.jar": {
"stateCleared": "modified",
},
Expand All @@ -25,6 +28,9 @@ exports[`generator - gradle with valid configuration should generate only gradle
".yo-rc.json": {
"stateCleared": "modified",
},
"buildSrc/build.gradle": {
"stateCleared": "modified",
},
"gradle/wrapper/gradle-wrapper.jar": {
"stateCleared": "modified",
},
Expand Down
2 changes: 1 addition & 1 deletion generators/gradle/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export default {
gradle: [
{
templates: ['.prettierignore.jhi.gradle', 'gradle/wrapper/gradle-wrapper.properties'],
templates: ['.prettierignore.jhi.gradle', 'gradle/wrapper/gradle-wrapper.properties', 'buildSrc/build.gradle'],
},
{
transform: false,
Expand Down
3 changes: 3 additions & 0 deletions generators/gradle/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
addGradlePluginCallback,
addGradlePluginManagementCallback,
addGradlePropertyCallback,
addGradleBuildSrcDependencyCallback,
} from './internal/needles.js';

export default class GradleGenerator extends BaseApplicationGenerator {
Expand Down Expand Up @@ -73,6 +74,8 @@ export default class GradleGenerator extends BaseApplicationGenerator {
source.addGradleMavenRepository = repository => this.editFile('build.gradle', addGradleMavenRepositoryCallback(repository));
source.addGradlePluginManagement = plugin => this.editFile('settings.gradle', addGradlePluginManagementCallback(plugin));
source.addGradleProperty = property => this.editFile('gradle.properties', addGradlePropertyCallback(property));
source.addGradleBuildSrcDependency = dependency =>
this.editFile('buildSrc/build.gradle', addGradleBuildSrcDependencyCallback(dependency));
},
});
}
Expand Down
6 changes: 6 additions & 0 deletions generators/gradle/internal/needles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const addGradleDependencyCallback = ({ groupId, artifactId, version, scop
contentToAdd: `${scope} "${groupId}:${artifactId}${version ? `:${version}` : ''}"`,
});

export const addGradleBuildSrcDependencyCallback = ({ groupId, artifactId, version, scope }: GradleDependency) =>
createNeedleCallback({
needle: 'gradle-build-src-dependency',
contentToAdd: `${scope} "${groupId}:${artifactId}${version ? `:${version}` : ''}"`,
});

export const addGradlePluginCallback = ({ id, version }: GradlePlugin) =>
createNeedleCallback({
needle: 'gradle-plugins',
Expand Down
5 changes: 5 additions & 0 deletions generators/gradle/needles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class mockBlueprintSubGen extends BaseApplicationGenerator {
source.addGradleDependency?.({ scope: 'scope4', groupId: 'group4', artifactId: 'name4' });
source.applyFromGradle?.({ script: 'name.gradle' });
source.addGradleMavenRepository?.({ url: 'url', username: 'username', password: 'password' });
source.addGradleBuildSrcDependency?.({ scope: 'scope5', groupId: 'group5', artifactId: 'name5', version: 'version5' });
},
});
}
Expand Down Expand Up @@ -71,4 +72,8 @@ describe('needle API server gradle: JHipster server generator with blueprint', (
' }',
);
});

it('Assert buildSrc/build.gradle has the Dependency with version added', () => {
runResult.assertFileContent('buildSrc/build.gradle', 'scope5 "group5:name5:version5"');
});
});
11 changes: 11 additions & 0 deletions generators/gradle/templates/buildSrc/build.gradle.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'groovy-gradle-plugin'
}

repositories {
gradlePluginPortal()
}

dependencies {
// jhipster-needle-gradle-build-src-dependency - JHipster will add additional dependencies for convention plugins here
}
1 change: 1 addition & 0 deletions generators/gradle/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export type GradleSourceType = {
addGradlePluginManagement?(pluginManagement: GradlePlugin): void;
addGradleProperty?(property: GradleProperty): void;
addGradleMavenRepository?(repository: GradleRepository): void;
addGradleBuildSrcDependency?(dependency: GradleDependency): void;
};
7 changes: 7 additions & 0 deletions generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ configurations {
implementation.exclude module: "spring-boot-starter-tomcat"
}

// workaround for https://github.com/checkstyle/checkstyle/issues/14123
configurations.checkstyle {
resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") {
select("com.google.guava:guava:0")
}
}

repositories {
// Local maven repository is required for libraries built locally with maven like development jhipster-bom.
<%= !jhipsterDependenciesVersion.includes('-SNAPSHOT') && !jhipsterDependenciesVersion.includes('-CICD') ? '// ' : '' %>mavenLocal()
Expand Down
Loading