Skip to content

Commit 795b80a

Browse files
committed
add hints using needles.
1 parent d6b4f11 commit 795b80a

File tree

3 files changed

+70
-33
lines changed

3 files changed

+70
-33
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ If you've enabled e2e testing with Cypress, you can verify its operation using t
7575
npm run native-e2e
7676
```
7777

78+
## Build errors
79+
80+
GraalVM uses metadata to generate AOT compilation.
81+
A metadata is designed to support an specific version. Missing library range will be added as best bet and will fall back to latest version.
82+
83+
Refer to [GraalVM Reachability Metadata Repository](https://github.com/oracle/graalvm-reachability-metadata/)
84+
7885
# Pre-release
7986

8087
To use an unreleased version, install it using npm + git repository.

generators/server/generator.js

+62-12
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { extname } from 'node:path';
44
import { passthrough } from '@yeoman/transform';
55
import { isFileStateDeleted, isFileStateModified } from 'mem-fs-editor/state';
66
import ServerGenerator from 'generator-jhipster/generators/base-application';
7-
import { javaMainPackageTemplatesBlock, addJavaAnnotation } from 'generator-jhipster/generators/java/support';
7+
import { javaMainPackageTemplatesBlock, addJavaAnnotation, addJavaImport } from 'generator-jhipster/generators/java/support';
88
import { lt as semverLessThan } from 'semver';
99

1010
import { NATIVE_BUILDTOOLS_VERSION } from '../../lib/constants.js';
1111
import { mavenDefinition } from './support/index.js';
12+
import { createNeedleCallback } from 'generator-jhipster/generators/base/support';
1213

1314
export default class extends ServerGenerator {
1415
blueprintVersion;
@@ -31,6 +32,33 @@ export default class extends ServerGenerator {
3132
});
3233
}
3334

35+
get [ServerGenerator.PREPARING]() {
36+
return this.asPreparingTaskGroup({
37+
addNativeHint({ source, application }) {
38+
source.addNativeHint = ({ publicConstructors = [], declaredConstructors = [] }) => {
39+
this.editFile(
40+
`${application.javaPackageSrcDir}config/NativeConfiguration.java`,
41+
addJavaImport('org.springframework.aot.hint.MemberCategory'),
42+
createNeedleCallback({
43+
contentToAdd: [
44+
...publicConstructors.map(
45+
classPath =>
46+
`hints.reflection().registerType(${classPath}, (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));`,
47+
),
48+
...declaredConstructors.map(
49+
classPath =>
50+
`hints.reflection().registerType(${classPath}, (hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));`,
51+
),
52+
],
53+
needle: 'add-native-hints',
54+
ignoreWhitespaces: true,
55+
}),
56+
);
57+
};
58+
},
59+
});
60+
}
61+
3462
get [ServerGenerator.DEFAULT]() {
3563
return this.asDefaultTaskGroup({
3664
// workaround for https://github.com/spring-projects/spring-boot/issues/32195
@@ -128,13 +156,37 @@ export default class extends ServerGenerator {
128156

129157
get [ServerGenerator.POST_WRITING]() {
130158
return this.asPostWritingTaskGroup({
131-
hints({ application: { mainClass, javaPackageSrcDir, packageName } }) {
159+
hints({ application, source }) {
160+
const { mainClass, javaPackageSrcDir, packageName } = application;
161+
132162
this.editFile(`${javaPackageSrcDir}${mainClass}.java`, { assertModified: true }, contents =>
133163
addJavaAnnotation(contents, { package: 'org.springframework.context.annotation', annotation: 'ImportRuntimeHints' }).replaceAll(
134164
'@ImportRuntimeHints\n',
135165
`@ImportRuntimeHints({ ${packageName}.config.NativeConfiguration.JHipsterNativeRuntimeHints.class })\n`,
136166
),
137167
);
168+
169+
if (application.databaseMigrationLiquibase) {
170+
// Latest liquibase version supported by Reachability Repository is 4.23.0
171+
// Hints may be dropped if newer version is supported
172+
// https://github.com/oracle/graalvm-reachability-metadata/blob/master/metadata/org.liquibase/liquibase-core/index.json
173+
source.addNativeHint({
174+
publicConstructors: ['liquibase.ui.LoggerUIService.class'],
175+
declaredConstructors: [
176+
'liquibase.database.LiquibaseTableNamesFactory.class',
177+
'liquibase.report.ShowSummaryGeneratorFactory.class',
178+
],
179+
});
180+
}
181+
182+
if (application.databaseTypeSql && !application.reactive) {
183+
// Latest hibernate-core version supported by Reachability Repository is 6.5.0.Final
184+
// Hints may be dropped if newer version is supported
185+
// https://github.com/oracle/graalvm-reachability-metadata/blob/master/metadata/org.hibernate.orm/hibernate-core/index.json
186+
source.addNativeHint({
187+
publicConstructors: ['org.hibernate.binder.internal.BatchSizeBinder.class'],
188+
});
189+
}
138190
},
139191

140192
async packageJson({ application: { buildToolMaven, buildToolGradle } }) {
@@ -243,16 +295,14 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;`,
243295
// workaround for arch error in backend:unit:test caused by gradle's org.graalvm.buildtools.native plugin
244296
technicalStructureTest({ application: { buildToolGradle, javaPackageTestDir } }) {
245297
if (!buildToolGradle) return;
246-
this.editFile(`${javaPackageTestDir}/TechnicalStructureTest.java`, { assertModified: true }, contents =>
247-
contents.includes('__BeanFactoryRegistrations')
248-
? contents
249-
: contents
250-
.replace(
251-
'import static com.tngtech.archunit.core.domain.JavaClass.Predicates.belongToAnyOf;',
252-
`import static com.tngtech.archunit.core.domain.JavaClass.Predicates.belongToAnyOf;
253-
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.simpleNameEndingWith;`,
254-
)
255-
.replace(
298+
this.editFile(
299+
`${javaPackageTestDir}/TechnicalStructureTest.java`,
300+
{ assertModified: true },
301+
addJavaImport('com.tngtech.archunit.core.domain.JavaClass.Predicates.simpleNameEndingWith'),
302+
contents =>
303+
contents.includes('__BeanFactoryRegistrations')
304+
? contents
305+
: contents.replace(
256306
'.ignoreDependency(belongToAnyOf',
257307
`.ignoreDependency(simpleNameEndingWith("_BeanFactoryRegistrations"), alwaysTrue())
258308
.ignoreDependency(belongToAnyOf`,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package <%=packageName%>.config;
22

3-
import org.springframework.aot.hint.MemberCategory;
43
import org.springframework.aot.hint.RuntimeHints;
54
import org.springframework.aot.hint.RuntimeHintsRegistrar;
65

@@ -11,27 +10,8 @@ public class NativeConfiguration {
1110
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
1211
<%_ if (databaseMigrationLiquibase) { _%>
1312
hints.resources().registerPattern("config/liquibase/*");
14-
15-
// https://github.com/oracle/graalvm-reachability-metadata/blob/master/metadata/org.liquibase/liquibase-core/index.json
16-
hints.reflection().registerType(
17-
liquibase.ui.LoggerUIService.class,
18-
(hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
19-
);
20-
hints.reflection().registerType(
21-
liquibase.database.LiquibaseTableNamesFactory.class,
22-
(hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)
23-
);
24-
hints.reflection().registerType(
25-
liquibase.report.ShowSummaryGeneratorFactory.class,
26-
(hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)
27-
);
28-
<%_ } _%>
29-
<%_ if (databaseTypeSql && !reactive) { _%>
30-
hints.reflection().registerType(
31-
org.hibernate.binder.internal.BatchSizeBinder.class,
32-
(hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)
33-
);
3413
<%_ } _%>
14+
// jhipster-needle-add-native-hints - JHipster will add native hints here
3515
}
3616
}
3717
}

0 commit comments

Comments
 (0)