Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-73850

springboot项目配置logback-spring.xml文件,含rollingPolicy标签打包不成功的问题

      框架springboot3.1.3+jdk17+gradle

      build.gradle文件内容如下:
      plugins {

      id 'java'

      id 'org.springframework.boot' version '3.1.3'

      id 'io.spring.dependency-management' version '1.1.3'

      }

       

      group = 'com.common'

       

      java {

      sourceCompatibility = '17'

      }

       

      repositories {

      mavenCentral()

      }

       

      ext {

      set('springCloudVersion', "2022.0.4")

      }

       

      dependencies {

      implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:2022.0.0.0'

      implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:2022.0.0.0'

      //Gateway

      implementation 'org.springframework.cloud:spring-cloud-starter-gateway'

      //Ribbon

      implementation 'org.springframework.cloud:spring-cloud-starter-loadbalancer'

      //JWT

      implementation 'io.jsonwebtoken:jjwt:0.9.1'

      implementation 'javax.xml.bind:jaxb-api:2.3.1'

      //Redis

      implementation 'org.springframework.boot:spring-boot-starter-data-redis:3.1.3'

      //JSON

      implementation 'com.alibaba.fastjson2:fastjson2:2.0.39'

      //自动get/set

      implementation 'org.projectlombok:lombok'

      //服务监控

      implementation 'org.springframework.boot:spring-boot-starter-actuator'

      developmentOnly 'org.springframework.boot:spring-boot-devtools'

      testImplementation 'org.springframework.boot:spring-boot-starter-test'

      testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.2'

      }

       

      // 清除目录lib下的依赖包

      task clearLibs(type: Delete) {

      delete "${buildDir}/libs/lib"

      }

       

      // 生成目录lib下的依赖包

      task copyLibs(type: Copy) {

      from configurations.runtimeClasspath

      into "${buildDir}/libs/lib"

      include "*.jar"

      }

       

      // 修改bootJar任务,使其不打包依赖库,并设置正确的Class-Path

      bootJar {

      excludes = ["*.jar"]

       

      // 配置jar任务依赖于多个任务,优先执行以下任务

      dependsOn clearLibs

      dependsOn copyLibs

       

      // 确保只包含编译后的类文件

      from sourceSets.main.output

      // 配置Class-Path读取依赖包目录

      doFirst {

      manifest {

      attributes(

      'Class-Path': configurations.runtimeClasspath.files.collect { "lib/${it.name}" }.join(' ')

      )

      }

      }

      }

       

      dependencyManagement {

      imports {

      mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"

      }

      }

       

      tasks.named('test') {

      useJUnitPlatform()

      }

       

      src/main/resources目录下的logback-spring.xml文件如下:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <configuration>

      <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />

      <!-- 从Nacos获取日志目录配置 -->

      <property name="LOG_DIR" value="/home/log/common-gateway"/>

       

      <!-- 定义日志文件的命名模式 -->

      <property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>

       

      <!-- Info日志 -->

      <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">

      <file>${LOG_DIR}/info.log</file>

      <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

      <fileNamePattern>${LOG_FILE_NAME}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>

      <maxHistory>30</maxHistory>

      <totalSizeCap>1GB</totalSizeCap>

      </rollingPolicy>

      <encoder>

      <pattern>${LOG_PATTERN}</pattern>

      </encoder>

      <filter class="ch.qos.logback.classic.filter.LevelFilter">

      <level>INFO</level>

      <onMatch>ACCEPT</onMatch>

      <onMismatch>DENY</onMismatch>

      </filter>

      </appender>

       

      <!-- Error日志 -->

      <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">

      <file>${LOG_DIR}/error.log</file>

      <!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->

      <!-- <fileNamePattern>${LOG_DIR}/error.%d{yyyy-MM-dd}.log</fileNamePattern>-->

      <!-- <maxHistory>30</maxHistory>-->

      <!-- </rollingPolicy>-->

      <encoder>

      <pattern>${LOG_PATTERN}</pattern>

      </encoder>

      <filter class="ch.qos.logback.classic.filter.LevelFilter">

      <level>ERROR</level>

      <onMatch>ACCEPT</onMatch>

      <onMismatch>DENY</onMismatch>

      </filter>

      </appender>

       

      <!-- 设置日志级别和输出的Appender -->

      <root level="INFO">

      <appender-ref ref="ERROR_FILE"/>

      <appender-ref ref="INFO_FILE"/>

      </root>

       

      </configuration>

      上述配置在spring tools suite上运行没有问题,可以正常运行,输出日志。但用jenkins(版本号:2.456)打包就报错如下:
      > git rev-list --no-walk f7d2ab227e4fc4ecd673c0952a75e29b9d5e7a45 # timeout=10
      [Gradle] - Launching build.
      [mes-common-gateway] $ /var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle8/bin/gradle clean build
      Starting a Gradle Daemon (subsequent builds will be faster)
      >
      Task :clean
      >
      Task :compileJava
      >
      Task :processResources
      >
      Task :classes
      >
      Task :clearLibs
      UP-TO-DATE>
      Task :copyLibs
      >
      Task :resolveMainClassName
      >
      Task :bootJar
      >
      Task :jar
      >
      Task :assemble
      >
      Task :compileTestJava
      >
      Task :processTestResources
      NO-SOURCE>
      Task :testClasses
      >
      Task :test
      CommonGatewayApplicationTests > contextLoads() FAILED
      java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:143
      Caused by: java.lang.IllegalStateException at LoggingApplicationListener.java:347
      Caused by: java.lang.IllegalStateException at LogbackLoggingSystem.java:269

      1 test completed, 1 failed

      >
      Task :test
      FAILED

      FAILURE: Build failed with an exception.

      Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

      You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

      For more on this, please refer to
      https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings
      in the Gradle documentation.BUILD FAILED in 19s
      10 actionable tasks: 9 executed, 1 up-to-date
      Build step 'Invoke Gradle script' changed build result to FAILURE
      Build step 'Invoke Gradle script' marked build as failure
      Finished: FAILURE

          [JENKINS-73850] springboot项目配置logback-spring.xml文件,含rollingPolicy标签打包不成功的问题

          Mark Waite added a comment -

          This looks like a request for assistance to diagnose a build failure in one of your Jenkins jobs. The Jenkins issue tracker is used to track bugs and enhancements requests. We use community.jenkins.io for question and answer. Please ask your question in that location or in the Jenkins user mailing list

          Mark Waite added a comment - This looks like a request for assistance to diagnose a build failure in one of your Jenkins jobs. The Jenkins issue tracker is used to track bugs and enhancements requests. We use community.jenkins.io for question and answer. Please ask your question in that location or in the Jenkins user mailing list

            Unassigned Unassigned
            lwc920719 L
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: