提问者:小点点

Gradle包括项目作为依赖不起作用


我正在尝试使用多个子项目创建一个Gradle项目,util依赖于api项目,两个项目位于同一目录下:

├── mainFolder
│   ...
├── api
│   ├── src
│   │   └──...
│   └── build.gradle
├── util
│   ├── src
│   │   └──...
│   └── build.gradle
└── settings.gradle

util项目build. gradle

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

group = 'my.package.util'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

ext {
    springBootVersion = '2.7.5'
}

dependencies {
    implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")

    implementation project(':api')
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

util项目设置. gradle

rootProject.name = 'util'

api项目build. gradle

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

group = 'my.package.api'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

ext {
    springBootVersion = '2.7.5'
}

dependencies {
    implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")

    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

api项目gradle. settings

rootProject.name = 'api'

主项目gradle. settings

include ':api'
include ':util'

但是在运行gradle build之后,我总是收到这个错误消息:

A problem occurred evaluating root project 'util'.
Project with path ':api' could not be found in root project 'util'.

我将感谢任何提示,提前感谢。


共1个答案

匿名用户

按照这个基本教程,我错过了一些配置并从build. gradle文件中删除了不必要的库。