gpt4 book ai didi

maven - 在自定义插件中使用 Gradle 依赖项

转载 作者:行者123 更新时间:2023-12-03 05:58:43 25 4
gpt4 key购买 nike

我正在尝试编写一个自定义 Gradle 插件,该插件使用他们的 API 调用 flyway 迁移:

https://flywaydb.org/documentation/api/

这是一个最小的例子:

buildscript {
repositories.jcenter()
dependencies.classpath "org.flywaydb:flyway-core:4.1.2"
}

apply plugin: DatabaseHandlerPlugin

class DatabaseHandlerPlugin implements Plugin<Project> {
void apply(Project project) {
project.task("databaseHandler").doLast {
org.flywaydb.Flyway f = new Flyway(); // <= How can I use the above declared dependency here and in my projects?
}
}
}

但是我的 gradle 提示它无法加载 Flyway 类。

最佳答案

Flyway 类位于 org.flywaydb.core包裹。您错过了 core少量。我的完整代码有效:

import org.flywaydb.core.Flyway; // << can import here

buildscript {
repositories { mavenCentral() }

dependencies {
classpath "org.flywaydb:flyway-core:4.1.2"
}

}
apply plugin: DatabaseHandlerPlugin

class DatabaseHandlerPlugin implements Plugin<Project> {
void apply(Project project) {
project.task('databaseHandler') {
doLast {
Flyway f = new Flyway()
println "Flyway: $f"
}
}
}
}

输出:
> gradle databaseHandler    
:databaseHandler
Flyway: org.flywaydb.core.Flyway@7b27e8f4

关于maven - 在自定义插件中使用 Gradle 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43220291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com