Skip to content

Commit

Permalink
[gradle] generate initial files for convention plugin usage
Browse files Browse the repository at this point in the history
udpates 19615
  • Loading branch information
atomfrede committed Dec 12, 2023
1 parent 9eb9eea commit 8e02b20
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 1 deletion.
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 @@ -17,6 +17,9 @@ exports[`generator - gradle with empty configuration should generate only gradle
"gradlew.bat": {
"stateCleared": "modified",
},
"buildSrc/build.gradle": {
"stateCleared": "modified"
}
}
`;

Expand All @@ -37,5 +40,8 @@ exports[`generator - gradle with valid configuration should generate only gradle
"gradlew.bat": {
"stateCleared": "modified",
},
"buildSrc/build.gradle": {
"stateCleared": "modified"
}
}
`;
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;
};

0 comments on commit 8e02b20

Please sign in to comment.