Gradle-使用Java 7的SpringBoot

时间:2018-09-05 01:21:31

标签: java spring-boot gradle

我有一个可以在Java 8上正常运行的SpringBoot应用程序。有人告诉我,我们将部署该应用程序的服务器只能运行Java 7或更低版​​本。它仍然是一个很小的应用程序,但我正在尝试仅更改build.gradle以使其起作用。我陷入了错误:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication : Unsupported major.minor version 52.0

这是我的build.gradle

buildscript {
    ext {
        springBootVersion = '1.5.16.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.menighin'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenCentral()
}


dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile('org.springframework.boot:spring-boot-starter-data-rest')
//  compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.session:spring-session-core')
    runtime('org.springframework.boot:spring-boot-devtools')
    compileOnly('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
//  testCompile('org.springframework.security:spring-security-test')
}

我刚放下springBootVersion,并将sourceCompatibilitytargetCompatibility设置为1.7。有什么想法我还需要更改为哪个版本? SpringBoot documentation on 1.5.16似乎已损坏:/

1 个答案:

答案 0 :(得分:0)

我认为无论如何都不会实现。该类/ JAR是为JDK 1.8编译的。因此是UnsupportedClassVersionError

无论如何,该版本为SNAPSHOT。我建议使用1.5.15 GA(您可以看到,只有较低的次要版本; p)...并且可以保证可以在Java 1.7上运行–除非撰写文档的人做错了什么。请参阅System Requirements