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

NoSuchMethodError exception when using ortools in Jhipster project #17409

Closed ptokponnon closed 2 years ago

ptokponnon commented 2 years ago
Overview of the issue

I am using google CPSat Solver Ortools in my Jhipster project. When I try to run with ./mvnw , I get a compilation error: Exception in thread "main" java.lang.NoSuchMethodError: com.google.protobuf.GeneratedMessageV3.isStringEmpty(Ljava/lang/Object;)Z Please, how to resolve it? Here is the output. $ ./mvnw

INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.mycompany.myapp:jhipster >--------------------
[INFO] Building JHipster 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.5.7:run (default-cli) > test-compile @ jhipster >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:copy-resources (default-resources) @ jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 6 resources
[INFO] Copying 16 resources
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 6 resources
[INFO] Copying 16 resources
[INFO] 
[INFO] --- maven-enforcer-plugin:3.0.0:enforce (enforce-versions) @ jhipster ---
[INFO] 
[INFO] --- maven-enforcer-plugin:3.0.0:enforce (enforce-dependencyConvergence) @ jhipster ---
[WARNING] The POM for org.apache.logging.log4j:log4j-api-java9:zip:2.14.1 is missing, no dependency information available
Downloading from spring-libs-release: https://repo.spring.io/libs-release/org/springframework/roo/org.springframework.roo.annotations/1.2.3.RELEASE/org.springframework.roo.annotations-1.2.3.RELEASE.pom
Downloading from spring-libs-snapshot: https://repo.spring.io/libs-snapshot/org/springframework/roo/org.springframework.roo.annotations/1.2.3.RELEASE/org.springframework.roo.annotations-1.2.3.RELEASE.pom
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Could not build dependency tree Could not collect dependencies: com.mycompany.myapp:jhipster:jar:0.0.1-SNAPSHOT ()
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.7:prepare-agent (pre-unit-tests) @ jhipster ---
[INFO] argLine set to -javaagent:[home]/.m2/repository/org/jacoco/org.jacoco.agent/0.8.7/org.jacoco.agent-0.8.7-runtime.jar=destfile=[Projects]/Jhipster/target/jacoco.exec -Djava.security.egd=file:/dev/./urandom -Xmx256m
[INFO] 
[INFO] --- properties-maven-plugin:1.0.0:read-project-properties (default) @ jhipster ---
[INFO] 
[INFO] --- checksum-maven-plugin:1.11:files (create-pre-compiled-webapp-checksum) @ jhipster ---
[INFO] 
[INFO] --- maven-antrun-plugin:3.0.0:run (eval-frontend-checksum) @ jhipster ---
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] 
[INFO] --- frontend-maven-plugin:1.12.0:install-node-and-npm (install-node-and-npm) @ jhipster ---
[INFO] Installing node version v14.18.1
[INFO] Unpacking [home]/.m2/repository/com/github/eirslett/node/14.18.1/node-14.18.1-linux-x64.tar.gz into [Projects]/Jhipster/target/node/tmp
[INFO] Copying node binary from [Projects]/Jhipster/target/node/tmp/node-v14.18.1-linux-x64/bin/node to [Projects]/Jhipster/target/node/node
[INFO] Installed node locally.
[INFO] Installing npm version 8.1.4
[INFO] Unpacking [home]/.m2/repository/com/github/eirslett/npm/8.1.4/npm-8.1.4.tar.gz into [Projects]/Jhipster/target/node/node_modules
[INFO] Installed npm locally.
[INFO] 
[INFO] --- frontend-maven-plugin:1.12.0:npm (npm install) @ jhipster ---
[INFO] Running 'npm install' in [Projects]/Jhipster
[INFO] 
[INFO] > jhipster@0.0.1-SNAPSHOT prepare
[INFO] > husky install
[INFO] 
[INFO] husky - Git hooks installed
[INFO] 
[INFO] up to date, audited 1854 packages in 5s
[INFO] 
[INFO] 196 packages are looking for funding
[INFO]   run `npm fund` for details
[INFO] 
[INFO] 11 moderate severity vulnerabilities
[INFO] 
[INFO] To address all issues (including breaking changes), run:
[INFO]   npm audit fix --force
[INFO] 
[INFO] Run `npm audit` for details.
[INFO] 
[INFO] --- frontend-maven-plugin:1.12.0:npm (webapp build dev) @ jhipster ---
[INFO] npm not inheriting proxy config from Maven
[INFO] Running 'npm run webapp:build' in [Projects]/Jhipster
[INFO] 
[INFO] > jhipster@0.0.1-SNAPSHOT webapp:build
[INFO] > npm run clean-www && npm run webapp:build:dev --
[INFO] 
[INFO] 
[INFO] > jhipster@0.0.1-SNAPSHOT clean-www
[INFO] > rimraf target/classes/static/app/{src,target/}
[INFO] 
[INFO] 
[INFO] > jhipster@0.0.1-SNAPSHOT webapp:build:dev
[INFO] > webpack --config webpack/webpack.dev.js --env stats=minimal
[INFO] 
Webpack: Starting ...
[INFO] 
[INFO]   ✔ Compile modules
[INFO]   ✔ Build modules
[INFO]   ✔ Optimize modules
[INFO]   ✔ Emit files
[INFO] 
[INFO] Finished after 18.169 seconds.
[INFO] 
Webpack: Starting ...
[INFO] 
[INFO]   ✔ Compile modules
[INFO]   ✔ Build modules
[INFO]   ✔ Optimize modules
[INFO]   ✔ Emit files
[INFO] 
[INFO] Finished after 3.163 seconds.
[INFO] 
[INFO] 47 assets
[INFO] 838 modules
[INFO] webpack 5.64.4 compiled successfully in 18139 ms
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ jhipster ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 73 source files to [Projects]/Jhipster/target/classes
[INFO] 
[INFO] --- checksum-maven-plugin:1.11:files (create-compiled-webapp-checksum) @ jhipster ---
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 7 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ jhipster ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 27 source files to [Projects]/Jhipster/target/test-classes
[INFO] [Projects]/Jhipster/src/test/java/com/mycompany/myapp/service/MailServiceIT.java: [Projects]/Jhipster/src/test/java/com/mycompany/myapp/service/MailServiceIT.java uses or overrides a deprecated API.
[INFO] [Projects]/Jhipster/src/test/java/com/mycompany/myapp/service/MailServiceIT.java: Recompile with -Xlint:deprecation for details.
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.5.7:run (default-cli) < test-compile @ jhipster <<<
[INFO] 
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.5.7:run (default-cli) @ jhipster ---
[INFO] Attaching agents: []
Exception in thread "main" java.lang.NoSuchMethodError: com.google.protobuf.GeneratedMessageV3.isStringEmpty(Ljava/lang/Object;)Z
    at com.google.ortools.sat.CpModelProto.getSerializedSize(CpModelProto.java:792)
    at com.google.protobuf.AbstractMessageLite.toByteArray(AbstractMessageLite.java:69)
    at com.google.ortools.sat.SolveWrapper.solve(SolveWrapper.java:56)
    at com.google.ortools.sat.CpSolver.solve(CpSolver.java:56)
    at com.google.ortools.sat.CpSolver.solveWithSolutionCallback(CpSolver.java:75)
    at com.google.ortools.sat.CpSolver.solve(CpSolver.java:38)
    at com.mycompany.myapp.CpSatExample.resolve(CpSatExample.java:35)
    at com.mycompany.myapp.JhipsterApp.main(JhipsterApp.java:67)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  42.979 s
[INFO] Finished at: 2021-12-23T13:24:06+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.7:run (default-cli) on project jhipster: Application finished with exit code: 1 -> [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/MojoExecutionException
Motivation for or Use Case

It works fine in a simple spring boot project. I have already tested it.

Reproduce the error

$jhipster


? Which *type* of application would you like to create? Monolithic application (re
commended for simple projects)
? What is the base name of your application? Jhipster
? Do you want to make it reactive with Spring WebFlux? No
? What is your default Java package name? com.mycompany.myapp
? Which *type* of authentication would you like to use? JWT authentication (statel
ess, with a token)
? Which *type* of database would you like to use? SQL (H2, PostgreSQL, MySQL, Mari
aDB, Oracle, MSSQL)
? Which *production* database would you like to use? MySQL
? Which *development* database would you like to use? H2 with disk-based persisten
ce
? Which cache do you want to use? (Spring cache abstraction) Ehcache (local cache,
 for a single node)
? Do you want to use Hibernate 2nd level cache? Yes
? Would you like to use Maven or Gradle for building the backend? Maven
? Do you want to use the JHipster Registry to configure, monitor and scale your ap
plication? No
? Which other technologies would you like to use? WebSockets using Spring Websocke
t
? Which *Framework* would you like to use for the client? React
? Do you want to generate the admin UI? Yes
? Would you like to use a Bootswatch theme (https://bootswatch.com/)? Default JHip
ster
? Would you like to enable internationalization support? Yes
? Please choose the native language of the application French
? Please choose additional languages to install English
? Besides JUnit and Jest, which testing frameworks would you like to use? Cypress
? Would you like to install other generators from the JHipster Marketplace? No
  1. Add ortools dependancy in the pom.xml file
        <dependency>
            <groupId>com.google.ortools</groupId>
            <artifactId>ortools-java</artifactId>
            <version>9.2.9972</version>
        </dependency>
  1. Create a simple CP Sat example class (from CP Problem ) and place it in the src/main/java/com/mycompany folder.
  2. In the CPSatExample.java, change the main() into resolve()
  3. In JhipsterApp.java, Call the solver
        public static void main(String[] args) {
             CpSatExample.resolve();
             .....
         }
Related issues
Suggest a Fix
JHipster Version(s)
JHipster configuration

Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
jhipster@0.0.1-SNAPSHOT /home/parfait/Programming/JavaScript/Jhipster
└── generator-jhipster@7.4.1
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "baseName": "Jhipster",
    "jhipsterVersion": "7.4.1",
    "skipUserManagement": false,
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "testFrameworks": ["cypress"],
    "blueprints": [],
    "otherModules": [],
    "pages": [],
    "creationTimestamp": 1640257236022,
    "serviceDiscoveryType": "no",
    "reactive": false,
    "authenticationType": "jwt",
    "packageName": "com.mycompany.myapp",
    "serverPort": "8080",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "buildTool": "maven",
    "serverSideOptions": ["websocket:spring-websocket"],
    "websocket": "spring-websocket",
    "searchEngine": false,
    "messageBroker": false,
    "enableSwaggerCodegen": false,
    "clientFramework": "react",
    "withAdminUi": true,
    "clientTheme": "none",
    "enableTranslation": true,
    "nativeLanguage": "fr",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "devServerPort": 9060,
    "clientPackageManager": "npm",
    "clientThemeVariant": "",
    "languages": ["fr", "en"],
    "enableGradleEnterprise": false
  }
}

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

Environment and Tools

java version "11.0.13" 2021-10-19 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.13+10-LTS-370) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.13+10-LTS-370, mixed mode)

git version 2.17.1

node: v14.18.0

npm: 7.24.1

Docker version 20.10.12, build e91ed57

docker-compose version 1.29.2, build 5becea4c

No change to package.json was detected. No package manager install will be executed.

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System

Ubuntu 18.04

ptokponnon commented 2 years ago

Here, I read that this is due to protobuf jar conflict, so I added the protobuf 's latest release in the pom.xml like this.

        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.19.1</version> 
        </dependency>

And it works.

mshima commented 2 years ago

Glad you fixed. Not related to jhipster.