javajhipsterupgrade

JHipster failed to upgrade from 8.1.0


My JHipster project was created on version 8.0.0 and then successfully upgraded to version 8.1.0. After that, there is error when I try to upgrade to 8.2.1 or 8.3.0 with the following error.

   create src\test\java\com\pccw\hktms\mp\config\RedisTestContainersSpringContextCustomizerFactory.java
ERROR! ERROR! Error parsing file src\main\java\com\pccw\hktms\mp\config\SecurityConfiguration.java: Error: Sad sad panda, parsing errors detected in line: 42, column: 9!
Expecting --> ';' <-- but found --> 'return' <--!
        ->compilationUnit
        ->ordinaryCompilationUnit
        ->typeDeclaration
        ->classDeclaration
        ->normalClassDeclaration
        ->classBody
        ->classBodyDeclaration
        ->classMemberDeclaration
        ->methodDeclaration
        ->methodBody
        ->block
        ->blockStatements
        ->blockStatement
        ->statement
        ->statementWithoutTrailingSubstatement
        ->expressionStatement at package com.pccw.hktms.mp.config;

import com.pccw.hktms.mp.security.*;
import tech.jhipster.config.JHipsterProperties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;


@Configuration
@EnableMethodSecurity(securedEnabled = true)
public class SecurityConfiguration {

    private final JHipsterProperties jHipsterProperties;

    public SecurityConfiguration( JHipsterProperties jHipsterProperties) {
        this.jHipsterProperties = jHipsterProperties;
    }

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc) throws Exception {
        http
            .csrf(csrf -> csrf
                .disable())
            .authorizeHttpRequests(authz ->
                // prettier-ignore
                authz
                    .requestMatchers(mvc.pattern("/api/authenticate")).permitAll()
                    .requestMatchers(mvc.pattern("/api/admin/**")).hasAuthority(AuthoritiesConstants.ADMIN)
                    .requestMatchers(mvc.pattern("/api/**")).authenticated()
                    .requestMatchers(mvc.pattern("/v3/api-docs/**")).hasAuthority(AuthoritiesConstants.ADMIN)
                    .requestMatchers(mvc.pattern("/management/health")).permitAll()
                    .requestMatchers(mvc.pattern("/management/health/**")).permitAll()
                    .requestMatchers(mvc.pattern("/management/info")).permitAll()
                    .requestMatchers(mvc.pattern("/management/prometheus")).permitAll()
                    .requestMatchers(mvc.pattern("/management/**")).hasAuthority(AuthoritiesConstants.ADMIN))
        return http.build();
    }

    @Bean
    MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) {
        return new MvcRequestMatcher.Builder(introspector);
    }
}
    at file:///C:/Users/02007425/IdeaProjects/mp-api/node_modules/generator-jhipster/dist/generators/bootstrap/support/java-unused-imports-transform.mjs:20:27
    at Transform.<anonymous> (file:///C:/Users/02007425/IdeaProjects/mp-api/node_modules/@yeoman/transform/dist/transform.js:42:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Transform.transform [as _transform] (file:///C:/Users/02007425/IdeaProjects/mp-api/node_modules/@yeoman/transform/dist/transform.js:16:37)
ERROR! An error occured while running jhipster:upgrade#prepareUpgradeBranch
ERROR! ERROR! Command failed with exit code 1: npx --no jhipster --force --skip-install --skip-git --ignore-errors --no-insight --skip-checks
Error: Command failed with exit code 1: npx --no jhipster --force --skip-install --skip-git --ignore-errors --no-insight --skip-checks
    at makeError (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/execa/lib/error.js:60:11)
    at handlePromise (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/execa/index.js:124:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async UpgradeGenerator.prepareUpgradeBranch (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/dist/generators/upgrade/generator.js:168:21)
    at async UpgradeGenerator.executeTask (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/yeoman-generator/dist/actions/lifecycle.js:244:13)
    at async runLoop.add.once (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/yeoman-environment/dist/environment-base.js:395:17) {
  shortMessage: 'Command failed with exit code 1: npx --no jhipster --force --skip-install --skip-git --ignore-errors --no-insight --skip-checks',

Clearly, it is missing a ; at the end of the line .requestMatchers(mvc.pattern("/management/**")).hasAuthority(AuthoritiesConstants.ADMIN)).

I've tried to update npm and node to the latest versions. But the same problem still exists.

>npm doctor
Check                      Value   Recommendation/Notes
npm ping                   ok
npm -v                     ok      current: v10.5.2, latest: v10.5.2
node -v                    ok      current: v20.12.2, recommended: v20.12.2
npm config get registry    ok      using default registry (https://registry.npmjs.org/)
git executable in PATH     ok      C:\Program Files\Git\cmd\git.EXE
global bin folder in PATH  ok      C:\Program Files\nodejs

Solution

  • There is no such problem when upgrading to version 8.5.0.

    Maybe the problem has been fixed.