Gradle Spring Boot项目无法从IDEA运行

时间:2017-07-21 13:13:48

标签: spring-boot intellij-idea gradle

我正在努力设置我在IntelliJ IDEA 2016 1.4中导入的弹簧启动项目。         每次我跑。我得到以下例外:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
        at com.patientConnect.DemoApplication.main(DemoApplication.java:24)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
    Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 6 more

我的gradle设置(链接的gradle项目,用户gradle包装器)看起来都很好。

package com.Demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public DemoApplication() {
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }


}

的build.gradle:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE'
        classpath 'gradle.plugin.com.jamesward:atom-gradle-plugin:0.0.1'
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'    

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-parent:1.5.4.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-devtools'
    compile 'org.springframework.boot:spring-boot-starter-security'
    compile 'org.springframework.security.oauth:spring-security-oauth2'

    compile 'org.apache.httpcomponents:httpclient'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'org.postgresql:postgresql'
    compile 'org.springframework.boot:spring-boot-starter-jdbc'
    compile 'org.hibernate:hibernate-entitymanager'


}

allprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}



import org.gradle.internal.os.OperatingSystem

task devClasses(type: Exec) {
    if (OperatingSystem.current().isWindows())
        commandLine 'gradlew', '-t', 'classes'
    else
        commandLine './gradlew', '-t', 'classes'
}

task devBootRun(type: Exec) {
    if (OperatingSystem.current().isWindows())
        commandLine 'gradlew', 'bootRun'
    else
        commandLine './gradlew', 'bootRun' //, '--debug-jvm'
}

import java.util.concurrent.*

task dev() << {
    def devClassesFuture = Executors.newSingleThreadExecutor().submit({ devClasses.execute() } as Callable)
    def devBootRunFuture = Executors.newSingleThreadExecutor().submit({ devBootRun.execute() } as Callable)
    devClassesFuture?.get()
    devBootRunFuture?.get()
}


task stage {
    dependsOn build
}

1 个答案:

答案 0 :(得分:0)

尝试删除计算机上的SpringBoot依赖项。

它位于~/.gradle/caches/modules-2/files-2.1/org.springframework.boot假设您将gradle依赖项保留在默认位置。

rm -rf ~/.gradle/caches/modules-2/files-2.1/org.springframework.boot

或删除所有依赖项(只是为了确保没有其他依赖项被破坏)

rm -rf ~/.gradle/caches/modules-2/files-2.1/*

然后重新下载

gradle build --refresh-dependencies