gpt4 book ai didi

gradle - Gradle插件执行命令

转载 作者:行者123 更新时间:2023-12-03 04:02:51 25 4
gpt4 key购买 nike

我已经写了这个gradle文件

group 'com.abhi'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'org.flywaydb.flyway'

sourceCompatibility = 1.8

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
classpath 'org.jooq:jooq-codegen:3.7.1'
classpath 'com.h2database:h2:1.4.177'
}
}

repositories {
mavenCentral()
}

dependencies {
compile group: 'org.jooq', name: 'jooq', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-meta', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-codegen', version: '3.7.1'
runtime group: 'com.h2database', name: 'h2', version: '1.4.177'
}

flyway {
url = 'jdbc:h2:file:target/foobar'
user = 'sa'
}

def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd') {
jdbc() {
driver('org.h2.Driver')
url('dbc:h2:file:target/foobar')
user('sa')
password('')
}
generator() {
database() {
}
generate() {
}
target() {
packageName('com.abhi.jooq.models')
directory('src/main/java')
}
}
}

// Run the code generator
// ----------------------
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)

当我说 gradle compile时会引发异常
Could not load schemata
java.lang.NullPointerException
at org.jooq.impl.MetaImpl.meta(MetaImpl.java:120)
at org.jooq.impl.MetaImpl.getCatalogs(MetaImpl.java:143)
at org.jooq.impl.MetaImpl.getSchemas(MetaImpl.java:168)
at org.jooq.util.jdbc.JDBCDatabase.getSchemasFromMeta(JDBCDatabase.java:135)
at org.jooq.util.jdbc.JDBCDatabase.getSchemata0(JDBCDatabase.java:124)
at org.jooq.util.AbstractDatabase.getSchemata(AbstractDatabase.java:279)

我认为问题在于脚本底部的代码在“flyway”插件之前执行了很多。

有没有办法确保仅在flyway插件执行后才执行以下代码?

最佳答案

是的,如果您认为问题出在执行顺序上,则可以像处理其他任何任务一样修改它。看看flyway plugin的文档。据此,此插件向您的构建脚本中添加了一些额外的任务,例如,一个任务是:flywayMigrateflywayClean等。您可以根据此插件中的任务来执行任何任务(使用dependsOn选项),并使它们仅运行插件的工作完成后。

关于gradle - Gradle插件执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793760/

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