简体   繁体   English

如何使用 Gradle 7 在 Spring 启动应用程序中添加外部 jar 文件依赖项?

[英]How to add external jar file dependencies in Spring boot app with Gradle 7?

I created a new Spring boot application with Intellij Idea.我使用 Intellij Idea 创建了一个新的 Spring 引导应用程序。 It has dependencies on some Jars which are our own.它依赖于我们自己的一些 Jars。 My Gradle file looks like this.我的 Gradle 文件看起来像这样。

plugins {
    id 'org.springframework.boot' version '2.5.0'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.company'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {

    compile files('lib/Common.jar')
    compile files('lib/ConnectionManager.jar')
    compile files('lib/LogManager.jar')
    compile files('lib/Licensing.jar')
    compile files('lib/Messaging.jar')
    compile files('lib/Communication.jar')


    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'com.h2database:h2'
    runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
    runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
    runtimeOnly 'mysql:mysql-connector-java'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'


}

test {
    useJUnitPlatform()
}

I tried to add dependencies of jar files using我尝试使用添加 jar 文件的依赖项

compile files('lib/Common.jar')
compile files('lib/ConnectionManager.jar')
compile files('lib/LogManager.jar')
compile files('lib/Licensing.jar')
compile files('lib/Messaging.jar')
compile files('lib/Communication.jar')

This approach has worked in applications developed previously.这种方法在以前开发的应用程序中有效。 I noticed that they were using Gradle version 6.xxx.我注意到他们使用的是 Gradle 版本 6.xxx。 Now this new app has Gradle version 7.xx.现在这个新应用程序有 Gradle 版本 7.xx。

I am getting following errors:我收到以下错误:

A problem occurred evaluating root project 'xxxxx'.
> Could not find method compile() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

How can I fix this?我怎样才能解决这个问题?

The compile configuration has been deprecated for a while and was removed in Gradle 7. You should use implementation instead. compile配置已被弃用一段时间,并在 Gradle 7 中删除。您应该改用implementation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM