jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.47k stars 4.02k forks source link

Generating a reactive monolith with Maven, PostgreSQL, and H2 results in a compile error #19626

Closed mraible closed 2 years ago

mraible commented 2 years ago
Overview of the issue

If you create a reactive monolith with the default databases, it fails to compile.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (default-testCompile) on project twenty-one-points: Compilation failure: Compilation failure:
[ERROR] /Users/mraible/Downloads/21p/src/test/java/org/jhipster/health/config/PostgreSqlTestContainer.java:[7,37] cannot find symbol
[ERROR]   symbol:   class PostgreSQLContainer
[ERROR]   location: package org.testcontainers.containers
[ERROR] /Users/mraible/Downloads/21p/src/test/java/org/jhipster/health/config/PostgreSqlTestContainer.java:[14,13] cannot find symbol
[ERROR]   symbol:   class PostgreSQLContainer
[ERROR]   location: class org.jhipster.health.config.PostgreSqlTestContainer
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

If I change my .yo-rc.json to use Gradle instead of Maven, it works just fine.

Motivation for or Use Case

Compilation should always work with a brand-new app.

Reproduce the error

Create a new reactive monolith and select the default databases.

Related issues

https://github.com/jhipster/generator-jhipster-react-native/issues/253#issuecomment-1234864036

Suggest a Fix

Not sure.

JHipster Version(s)
twenty-one-points@0.0.1-SNAPSHOT /Users/mraible/Downloads/21p
└── generator-jhipster@7.9.3
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "TwentyOnePoints",
    "blueprints": [],
    "buildTool": "maven",
    "cacheProvider": "no",
    "clientFramework": "angularX",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1662134563019,
    "cypressAudit": false,
    "cypressCoverage": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": false,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entitySuffix": "",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.9.3",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "languages": ["en", "fr"],
    "messageBroker": false,
    "microfrontend": false,
    "microfrontends": [],
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "org.jhipster.health",
    "pages": [],
    "prodDatabaseType": "postgresql",
    "reactive": true,
    "searchEngine": "elasticsearch",
    "serverPort": "8080",
    "serverSideOptions": ["searchEngine:elasticsearch"],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": ["cypress"],
    "websocket": false,
    "withAdminUi": true
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

Environment and Tools

openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7) OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode)

git version 2.32.1 (Apple Git-133)

node: v16.16.0

npm: 8.18.0

Docker version 20.10.17, build 100c701

Docker Compose version v2.7.0

mshima commented 2 years ago

I’ve identified the problem. It’s related to: https://github.com/jhipster/generator-jhipster/blob/14a116c2644c3a150f8ccfad0734faf9ec8348c0/generators/server/templates/pom.xml.ejs#L2217-L2233

Happens only with Mac and m1 processor. Due to how maven works. When a profile is activated, activateByDefault profiles are deactivated.

If the dependency is still required, the only fix is to start using properties to activate profiles. ./mvnw -Dprod instead of ./mvnw -Pprod. IMO this is a breaking change and can be done for v8.

mraible commented 2 years ago

If it's M1-only, it's not a big deal, IMO. Is there a workaround for M1s in the meantime? Can I just add this classifier to the netty dependency?

mshima commented 2 years ago

Need to test:

mraible commented 2 years ago

If I remove the profile, the app still starts and e2e tests pass. There's just a stacktrace on startup:

2022-09-02T16:27:53.083-06:00 ERROR 81783 --- [  restartedMain] i.n.r.d.DnsServerAddressStreamProviders  : Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS. 

java.lang.reflect.InvocationTargetException: null
...
Caused by: java.lang.UnsatisfiedLinkError: failed to load the required native library
        at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.ensureAvailability(MacOSDnsServerAddressStreamProvider.java:110)
        at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.<init>(MacOSDnsServerAddressStreamProvider.java:120)
        ... 80 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: could not load a native library: netty_resolver_dns_native_macos_aarch_64
        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239)
        at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.loadNativeLibrary(MacOSDnsServerAddressStreamProvider.java:92)
        at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.<clinit>(MacOSDnsServerAddressStreamProvider.java:77)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:467)
        at io.netty.resolver.dns.DnsServerAddressStreamProviders$1.run(DnsServerAddressStreamProviders.java:50)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at io.netty.resolver.dns.DnsServerAddressStreamProviders.<clinit>(DnsServerAddressStreamProviders.java:46)
        ... 74 common frames omitted
        Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_resolver_dns_native_macos
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:239)
                at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.loadNativeLibrary(MacOSDnsServerAddressStreamProvider.java:95)
                ... 80 common frames omitted
        Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_resolver_dns_native_macos.jnilib
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:181)
                ... 81 common frames omitted
                Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos in java.library.path: /Users/mraible/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                        at java.base/java.lang.System.loadLibrary(System.java:1989)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:391)
                        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                        ... 81 common frames omitted
                        Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos in java.library.path: /Users/mraible/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
                                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                                at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                                at java.base/java.lang.System.loadLibrary(System.java:1989)
                                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                                at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:425)
                                at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:417)
                                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:383)
                                ... 82 common frames omitted
Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_resolver_dns_native_macos_aarch_64.jnilib
        at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:181)
        ... 81 common frames omitted
        Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos_aarch_64 in java.library.path: /Users/mraible/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
                at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                at java.base/java.lang.System.loadLibrary(System.java:1989)
                at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:391)
                at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:161)
                ... 81 common frames omitted
                Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos_aarch_64 in java.library.path: /Users/mraible/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
                        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
                        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
                        at java.base/java.lang.System.loadLibrary(System.java:1989)
                        at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
                        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
                        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
                        at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:425)
                        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:417)
                        at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:383)
                        ... 82 common frames omitted
mraible commented 2 years ago

Adding the dependency to the pom.xml as a regular dependency makes the stack trace go away:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-resolver-dns-native-macos</artifactId>
    <classifier>osx-aarch_64</classifier>
</dependency>
mraible commented 2 years ago

I tried the above fix on an Intel-based MacBook Pro and everything works too.

To folks finding this issue and needing a workaround:

  1. Remove the profile that contains netty-resolver-dns-native-macos at the bottom of your pom.xml
  2. Add the following dependency to the main <dependencies> section:

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-resolver-dns-native-macos</artifactId>
        <classifier>osx-aarch_64</classifier>
    </dependency>