Gradle没有看到Spring包,但是声明了一个依赖项

时间:2019-07-28 09:07:23

标签: java gradle dependencies

我正在做我的新项目。但是当我尝试构建它时,gradle返回错误:

 error: package org.springramework.transaction does not exist
import org.springframework.transaction.PlatformTransactionManager;

error: package org.springramework.orm.hibernate5 does not exist
import org.springframework.orm.hibernate5.HibernateTransactionManager;

这是我的build.gradle:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
    }
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'

compileJava.options.encoding = 'UTF-8'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

def tomcatVersion = '9.0.22'
dependencies {
    testImplementation 'junit:junit:4.12'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:8.5.2",
            "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion},"

    testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
    testCompile group: 'org.mockito', name: 'mockito-all', version: '1.8.4'
}

tomcat {
    httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol'
    ajpProtocol  = 'org.apache.coyote.ajp.AjpNio2Protocol'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.apache.tomcat:tomcat-dbcp:9.0.22'
    implementation 'org.postgresql:postgresql:42.2.6'
    implementation 'org.springframework:spring-context:5.1.8.RELEASE'
    implementation 'org.springframework:spring-webmvc:5.1.8.RELEASE'
    implementation 'org.springframework:spring-orm:5.1.8.RELEASE'
    implementation 'org.springframework:spring-tx:5.1.8.RELEASE'
    implementation 'org.hibernate:hibernate-core:5.4.1.Final'
}

关于spring上下文导入没有错误。 我知道,这很奇怪,但是在文件夹中 ~/.gradle/caches/modules-2/files-2.1/org.springframework上有带有jar的spring-orm和spring-tx文件夹。 我在做什么错了?

0 个答案:

没有答案