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

JHipster 8 modularization integration. #409

Merged
merged 12 commits into from
Jul 29, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/angular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ jobs:
node-version: 20
java-version: 11
binary-dir: ${{ github.workspace }}/jhipster-kotlin/cli
- run: |
mkdir -p ~/.gradle
echo "org.gradle.warning.mode=all" >> ~/.gradle/gradle.properties
- name: 'SETUP: environment'
id: setup
uses: ./jhipster-kotlin/.github/actions/setup
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ jobs:
node-version: 20
java-version: 11
binary-dir: ${{ github.workspace }}/jhipster-kotlin/cli
- run: |
mkdir -p ~/.gradle
echo "org.gradle.warning.mode=all" >> ~/.gradle/gradle.properties
- name: 'SETUP: environment'
id: setup
uses: ./jhipster-kotlin/.github/actions/setup
Expand Down
15 changes: 5 additions & 10 deletions generators/detekt/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

exports[`SubGenerator detekt of kotlin JHipster blueprint > gradle > should match source calls 1`] = `
{
"addGradlePluginToBuildScript": [
"addGradleDependencyCatalogPlugin": [
{
"group": "io.gitlab.arturbosch.detekt",
"name": "detekt-gradle-plugin",
"version": "\${detekt_version}",
},
],
"addGradleProperty": [
{
"property": "detekt_version",
"value": "'DETEKT-GRADLE-VERSION'",
"addToBuild": true,
"id": "io.gitlab.arturbosch.detekt",
"pluginName": "detekt",
"version": "'DETEKT-GRADLE-VERSION'",
},
],
"applyFromGradle": [
Expand Down
24 changes: 5 additions & 19 deletions generators/detekt/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,12 @@ export default class extends BaseApplicationGenerator {
if (application.buildToolGradle) {
source.applyFromGradle({ script: 'gradle/detekt.gradle' });

source.addGradleProperty({ property: 'detekt_version', value: application.javaDependencies['detekt-gradle'] });

source.addGradlePluginToBuildScript({
group: 'io.gitlab.arturbosch.detekt',
name: 'detekt-gradle-plugin',
version: '${detekt_version}',
source.addGradleDependencyCatalogPlugin({
pluginName: 'detekt',
id: 'io.gitlab.arturbosch.detekt',
version: application.javaDependencies['detekt-gradle'],
addToBuild: true,
});

/*
// JHipster 8 based configuration
source.addJavaDefinition({
versions: [
{ name: 'detekt', version: DETEKT_VERSION },
],
});

source.addGradleDependencyCatalogPlugins([
{ pluginName: 'detekt', id: 'io.gitlab.arturbosch.detekt', version: application.javaDependencies['detekt-gradle'], addToBuild: true },
]);
*/
}
},

Expand Down
2 changes: 0 additions & 2 deletions generators/detekt/templates/gradle/detekt.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
apply plugin: "io.gitlab.arturbosch.detekt"

detekt {
input = files("src/main/kotlin")
config = files("<%= detektConfigFile %>")
Expand Down
52 changes: 40 additions & 12 deletions generators/kotlin/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,55 @@

exports[`SubGenerator kotlin of kotlin JHipster blueprint > gradle > should match source calls 1`] = `
{
"addGradlePluginToBuildScript": [
"addGradleDependencyCatalogLibrary": [
{
"group": "org.jetbrains.kotlin",
"name": "kotlin-gradle-plugin",
"version": "\${kotlin_version}",
"libraryName": "kotlin-bom",
"name": "kotlin-bom",
"scope": "implementation platform",
"version.ref": "kotlin",
},
],
"addGradleDependencyCatalogPlugin": [
{
"group": "org.jetbrains.kotlin",
"name": "kotlin-allopen",
"version": "\${kotlin_version}",
"addToBuild": true,
"id": "org.jetbrains.kotlin.plugin.spring",
"pluginName": "kotlin-spring",
"version.ref": "kotlin",
},
{
"group": "org.jetbrains.kotlin",
"name": "kotlin-noarg",
"version": "\${kotlin_version}",
"addToBuild": true,
"id": "org.jetbrains.kotlin.plugin.jpa",
"pluginName": "kotlin-jpa",
"version.ref": "kotlin",
},
{
"addToBuild": true,
"id": "org.jetbrains.kotlin.plugin.allopen",
"pluginName": "kotlin-allopen",
"version.ref": "kotlin",
},
],
"addGradleProperty": [
"addGradleDependencyCatalogPlugins": [
[
{
"addToBuild": true,
"id": "org.jetbrains.kotlin.jvm",
"pluginName": "kotlin",
"version.ref": "kotlin",
},
{
"addToBuild": true,
"id": "org.jetbrains.kotlin.kapt",
"pluginName": "kotlin-kapt",
"version.ref": "kotlin",
},
],
],
"addGradleDependencyCatalogVersion": [
{
"property": "kotlin_version",
"value": "'KOTLIN-VERSION'",
"name": "kotlin",
"version": "'KOTLIN-VERSION'",
},
],
"applyFromGradle": [
Expand Down
81 changes: 37 additions & 44 deletions generators/kotlin/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,64 +77,57 @@ export default class extends BaseApplicationGenerator {
return this.asPostWritingTaskGroup({
async customizeGradle({ application, source }) {
if (application.buildToolGradle) {
source.addGradleDependencyCatalogVersion({ name: 'kotlin', version: application.javaDependencies.kotlin });

source.applyFromGradle({
script: 'gradle/kotlin.gradle',
});

source.addGradleProperty({ property: 'kotlin_version', value: application.javaDependencies.kotlin });
source.addGradleDependencyCatalogPlugins([
{
pluginName: 'kotlin',
id: 'org.jetbrains.kotlin.jvm',
'version.ref': 'kotlin',
addToBuild: true,
},
{
pluginName: 'kotlin-kapt',
id: 'org.jetbrains.kotlin.kapt',
'version.ref': 'kotlin',
addToBuild: true,
},
]);

source.addGradlePluginToBuildScript({
source.addGradleDependencyCatalogLibrary({
libraryName: 'kotlin-bom',
group: 'org.jetbrains.kotlin',
name: 'kotlin-gradle-plugin',
version: '${kotlin_version}',
name: 'kotlin-bom',
scope: 'implementation platform',
'version.ref': 'kotlin',
});

if (application.backendTypeSpringBoot) {
// Required for Spring plugin
source.addGradlePluginToBuildScript({
group: 'org.jetbrains.kotlin',
name: 'kotlin-allopen',
version: '${kotlin_version}',
source.addGradleDependencyCatalogPlugin({
pluginName: 'kotlin-spring',
id: 'org.jetbrains.kotlin.plugin.spring',
'version.ref': 'kotlin',
addToBuild: true,
});
if (application.databaseTypeSql) {
// Required for JPA plugin
source.addGradlePluginToBuildScript({
group: 'org.jetbrains.kotlin',
name: 'kotlin-noarg',
version: '${kotlin_version}',
source.addGradleDependencyCatalogPlugin({
pluginName: 'kotlin-jpa',
id: 'org.jetbrains.kotlin.plugin.jpa',
'version.ref': 'kotlin',
addToBuild: true,
});
}
}

/*
// JHipster 8 based configuration
source.addJavaDefinition({
versions: [
{ name: 'kotlin', version: KOTLIN_VERSION },
],
});

source.addGradleDependencyCatalogPlugins([
{ pluginName: 'kotlin-jvm', id: 'org.jetbrains.kotlin.jvm', 'version.ref': 'kotlin', addToBuild: true },
// Required for Spring plugin
{
pluginName: 'kotlin-allopen',
id: 'org.jetbrains.kotlin.plugin.allopen',
'version.ref': 'kotlin',
addToBuild: true,
},
]);
if (application.databaseTypeSql) {
// Required for JPA plugin
source.addGradleDependencyCatalogPlugins([
{
pluginName: 'kotlin-noarg',
id: 'org.jetbrains.kotlin.plugin.noarg',
source.addGradleDependencyCatalogPlugin({
pluginName: 'kotlin-allopen',
id: 'org.jetbrains.kotlin.plugin.allopen',
'version.ref': 'kotlin',
addToBuild: true,
},
]);
});
}
}
*/
}
},
async customizeMaven({ application, source }) {
Expand Down
38 changes: 15 additions & 23 deletions generators/kotlin/templates/gradle/kotlin.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,41 @@
-%>
import org.gradle.internal.os.OperatingSystem

apply plugin: "kotlin" // Required for Kotlin integration
apply plugin: "kotlin-kapt" // Required for annotations processing
apply plugin: "kotlin-spring" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
<%_ if (databaseTypeSql) { _%>
apply plugin: "kotlin-allopen" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#using-in-gradle
apply plugin: "kotlin-jpa" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#jpa-support
<%_ } _%>

apply plugin: "org.jlleitschuh.gradle.ktlint"

dependencies {
implementation platform("org.jetbrains.kotlin:kotlin-bom:${kotlin_version}")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-reflect"

<%_ if (reactive) { _%>
<%_ if (reactive) { _%>
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-debug"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-reactor"
implementation "io.projectreactor.kotlin:reactor-kotlin-extensions"
<%_ } _%>

<%_ } _%>
kapt "org.mapstruct:mapstruct-processor:${mapstructVersion}"
<%_ if (databaseTypeSql) { _%>
<%_ if (databaseTypeSql) { _%>
kapt "org.hibernate:hibernate-jpamodelgen:${hibernateVersion}"
kapt "org.glassfish.jaxb:jaxb-runtime:${jaxbRuntimeVersion}"
<%_ } _%>
<%_ if (databaseTypeCassandra) { _%>
<%_ } _%>
<%_ if (databaseTypeCassandra) { _%>
kapt "com.datastax.oss:java-driver-mapper-processor:${cassandraDriverVersion}"
<%_ } _%>
<%_ } _%>

testImplementation "org.jetbrains.kotlin:kotlin-test-junit"

testImplementation "org.mockito.kotlin:mockito-kotlin:<%= javaDependencies['mockito-kotlin'] %>"
}<%_ if (databaseTypeSql) { %>
}

kapt {
correctErrorTypes true
}

<%_ if (databaseTypeSql) { _%>
allOpen {
annotation("javax.persistence.Entity")
annotation("javax.persistence.MappedSuperclass")
annotation("javax.persistence.Embeddable")
}<%_ } %>
}

<%_ } _%>
[compileKotlin, compileTestKotlin]*.with {
kotlinOptions {
jvmTarget = "<%= javaVersion %>"
Expand All @@ -70,7 +64,6 @@ allOpen {
ktlint {
//See more options: https://github.com/JLLeitschuh/ktlint-gradle#configuration
ignoreFailures = true
disabledRules = ["no-wildcard-imports", "filename"]
}

if (OperatingSystem.current().isWindows()) {
Expand All @@ -81,10 +74,9 @@ if (OperatingSystem.current().isWindows()) {
}
}

//Reformat code before compilation
// Reformat code before compilation
compileKotlin.dependsOn ktlintFormat


jacocoTestReport {
// Add Kotlin sources to Jacoco source dirs
sourceDirectories.from += sourceSets.main.kotlin.srcDirs
Expand Down
15 changes: 9 additions & 6 deletions generators/ktlint/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

exports[`SubGenerator kotlin of kotlin JHipster blueprint > gradle > should match source calls 1`] = `
{
"addGradlePluginToBuildScript": [
{
"group": "org.jlleitschuh.gradle",
"name": "ktlint-gradle",
"version": "'KTLINT-GRADLE-VERSION'",
},
"addGradleDependencyCatalogPlugins": [
[
{
"addToBuild": true,
"id": "org.jlleitschuh.gradle.ktlint",
"pluginName": "ktlint",
"version": "'KTLINT-GRADLE-VERSION'",
},
],
],
}
`;
Expand Down
17 changes: 8 additions & 9 deletions generators/ktlint/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,14 @@ export default class extends BaseApplicationGenerator {
},
addDependencies({ application, source }) {
if (application.buildToolGradle) {
source.addGradlePluginToBuildScript({
group: 'org.jlleitschuh.gradle',
name: 'ktlint-gradle',
version: application.javaDependencies['ktlint-gradle'],
});

/* JHipster 8 based configuration
source.addGradleDependencyCatalogPlugins([{ pluginName: 'ktlint', id: 'org.jlleitschuh.gradle.ktlint', version: KTLINT_GRADLE_VERSION, addToBuild: true }]);
*/
source.addGradleDependencyCatalogPlugins([
{
pluginName: 'ktlint',
id: 'org.jlleitschuh.gradle.ktlint',
version: application.javaDependencies['ktlint-gradle'],
addToBuild: true,
},
]);
} else {
source.addJavaDefinition({
versions: [{ name: 'ktlint-maven-plugin', version: application.javaDependencies['ktlint-maven'] }],
Expand Down
Loading
Loading