最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Sonarqube running on Docker throws Error status returned by url [https: api.sonarcloud.ioanalysisjres?os=windows&

programmeradmin3浏览0评论

I tried to run sonarqube running on docker for my Spring Boot Project. I have a problem to get sonarqube result.

Here is my sonarqube plugin in my pom.xml

<plugin>
    <groupId>.sonarsource.scanner.maven</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>${sonar-maven-plugin.version}</version>
</plugin>

Here is the docker-compose.yml

services:

  postgres:
    image: postgres:latest
    container_name: postgres-container
    restart: always
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=weatherapianalysisdatabase
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - weatherapianalysis_network

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: pgadmin-container
    restart: always
    ports:
      - "5050:80"
    environment:
      - [email protected]
      - PGADMIN_DEFAULT_PASSWORD=admin
    depends_on:
      - postgres
    networks:
      - weatherapianalysis_network

  weatherapianalysis:
    image: 'weatherapianalysis:latest'
    build:
      context: .
      dockerfile: Dockerfile
    container_name: weatherapianalysis
    restart: on-failure
    env_file:
      - .env  # Use the .env file for environment variables
    ports:
      - "1100:1100"
    environment:
      - server.port=1100
      - WEATHER_DB_IP=postgres
      - WEATHER_DB_PORT=5432
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - OPEN_WEATHER_API_KEY=${OPEN_WEATHER_API_KEY:-open_weather_api_default_key}
    depends_on:
      - postgres
    networks:
      - weatherapianalysis_network

  sonarqube:
    image: sonarqube:latest
    container_name: sonarqube
    restart: always
    ports:
      - "9000:9000"
    environment:
      - SONAR_JDBC_URL=jdbc:postgresql://postgres:5432/weatherapianalysisdatabase
      - SONAR_JDBC_USERNAME=${POSTGRES_USER}
      - SONAR_JDBC_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
    depends_on:
      - postgres
    networks:
      - weatherapianalysis_network

volumes:
  postgres_data:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:

networks:
  weatherapianalysis_network:

Here is thr sonar-project.properties

# Project identification
sonar.projectKey=weatherapianalysis
sonar.projectName=Weather API Analysis
sonar.projectVersion=1.0

# SonarQube Server
sonar.host.url=http://localhost:9000

# Authentication Token (replace with your token from SonarQube)
sonar.token=token

# Language & Source Code
sonar.language=java
sonar.sources=src
sonar.tests=src/test
sonar.sourceEncoding=UTF-8
sonar.java.binaries=target/classes

After I created token through My Account > Security > Generate a Token , I copied the new token and updated sonar-project.properties

When I run this command mvn clean verify sonar:sonar , I got this issue shown below

[ERROR] Failed to execute goal .sonarsource.scanner.maven:sonar-maven-plugin:5.0.0.4389:sonar (default-cli) on project weatherapianalysis: Error status returned by url [https://
api.sonarcloud.io/analysis/jres?os=windows&arch=amd64]: 401 -> [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] 

How can I fix the issue?

I tried to run sonarqube running on docker for my Spring Boot Project. I have a problem to get sonarqube result.

Here is my sonarqube plugin in my pom.xml

<plugin>
    <groupId>.sonarsource.scanner.maven</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>${sonar-maven-plugin.version}</version>
</plugin>

Here is the docker-compose.yml

services:

  postgres:
    image: postgres:latest
    container_name: postgres-container
    restart: always
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=weatherapianalysisdatabase
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - weatherapianalysis_network

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: pgadmin-container
    restart: always
    ports:
      - "5050:80"
    environment:
      - [email protected]
      - PGADMIN_DEFAULT_PASSWORD=admin
    depends_on:
      - postgres
    networks:
      - weatherapianalysis_network

  weatherapianalysis:
    image: 'weatherapianalysis:latest'
    build:
      context: .
      dockerfile: Dockerfile
    container_name: weatherapianalysis
    restart: on-failure
    env_file:
      - .env  # Use the .env file for environment variables
    ports:
      - "1100:1100"
    environment:
      - server.port=1100
      - WEATHER_DB_IP=postgres
      - WEATHER_DB_PORT=5432
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - OPEN_WEATHER_API_KEY=${OPEN_WEATHER_API_KEY:-open_weather_api_default_key}
    depends_on:
      - postgres
    networks:
      - weatherapianalysis_network

  sonarqube:
    image: sonarqube:latest
    container_name: sonarqube
    restart: always
    ports:
      - "9000:9000"
    environment:
      - SONAR_JDBC_URL=jdbc:postgresql://postgres:5432/weatherapianalysisdatabase
      - SONAR_JDBC_USERNAME=${POSTGRES_USER}
      - SONAR_JDBC_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
    depends_on:
      - postgres
    networks:
      - weatherapianalysis_network

volumes:
  postgres_data:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:

networks:
  weatherapianalysis_network:

Here is thr sonar-project.properties

# Project identification
sonar.projectKey=weatherapianalysis
sonar.projectName=Weather API Analysis
sonar.projectVersion=1.0

# SonarQube Server
sonar.host.url=http://localhost:9000

# Authentication Token (replace with your token from SonarQube)
sonar.token=token

# Language & Source Code
sonar.language=java
sonar.sources=src
sonar.tests=src/test
sonar.sourceEncoding=UTF-8
sonar.java.binaries=target/classes

After I created token through My Account > Security > Generate a Token , I copied the new token and updated sonar-project.properties

When I run this command mvn clean verify sonar:sonar , I got this issue shown below

[ERROR] Failed to execute goal .sonarsource.scanner.maven:sonar-maven-plugin:5.0.0.4389:sonar (default-cli) on project weatherapianalysis: Error status returned by url [https://
api.sonarcloud.io/analysis/jres?os=windows&arch=amd64]: 401 -> [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./confluence/display/MAVEN/MojoExecutionException

How can I fix the issue?

Share Improve this question edited Feb 17 at 10:53 Sercan Noyan Germiyanoğlu asked Feb 16 at 19:33 Sercan Noyan GermiyanoğluSercan Noyan Germiyanoğlu 2,7314 gold badges53 silver badges124 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Can you try to replace sonar.login with sonar.token ? I think sonar.login is used to provide a username for the deprecated authentication mode user+psw, you should instead provide a token through "sonar.token"

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论