gradleant任务性能下降(xdoclet)

uubf1zoe  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(406)

已经将一个旧的maven构建迁移到gradle,并且在转换后有一个重要的问题。
该项目使用xdoclet生成hibernate.cfg.xml。在生成这个文件时,gradle将比maven平均增加2倍的构建时间。使用 inputs/outputs 为了避免后续构建中的工作,gradle花了maven一半的时间来构建。
因此,这个生成hibernate.cfg.xml的初始构建极大地影响了采用。
下面是gradle任务(改编自maven-antrun执行):

task generateHibernateConfig {
    outputs.file( file("${project.projectDir}/src/main/resources/hibernate.cfg.xml") )
    doLast {
        ant.echo(message: "Generating Hibernate Configuration")
        ant.taskdef(
                name: "hibernatedoclet",
                classname: "xdoclet.modules.hibernate.HibernateDocletTask",
                classpath: ant.references["xdoclet.task.classpath"]
        )
        ant.hibernatedoclet(destDir: "${project.projectDir}/src/main/resources",
            verbose: "false"
        ) {
            fileset(dir: "${project.projectDir}/src/main/java") {
                include(name: "**/*.java")
                // a few excluded classes redacted
            }
            hibernate(version: "3.0")
            hibernatecfg(dialect: "org.hibernate.dialect.DB2Dialect",
                    dataSource: "java:comp/env/jdbc/Example",
                    transactionManagerFactory: "org.hibernate.transaction.CMTTransactionFactory",
                    transactionManagerLookup: "org.hibernate.transaction.WebSphereExtendedJTATransactionLookup",
                    showSql: "false",
                    version: "3.0") {
                otherProperty(name: "hibernate.cache.use_second_level_cache", value: "true")
                otherProperty(name: "hibernate.cache.use_query_cache", value: "true")
                otherProperty(name: "hibernate.cache.region.factory_class", value: "net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory")
                otherProperty(name: "hibernate.transaction.flush_before_completion", value: "true")
                otherProperty(name: "hibernate.transaction.auto_close_session", value: "true")
                otherProperty(name: "hibernate.connection.provider_class", value: "org.hibernate.connection.DatasourceConnectionProvider")
                otherProperty(name: "hibernate.jdbc.use_get_generated_keys", value: "false")
            }
        }
    }
}

所需的类通过以下方式导入:

ant.path(id: "xdoclet.task.classpath", location: configurations.antBuild.asPath)

dependencies 关闭:

antBuild libs.xdoclet
    antBuild libs.xdocletFixedHibernate
    antBuild libs.xdocletModule
    antBuild libs.xdocletJavadoc
    antBuild libs.log4j
    antBuild libs.hibernateCore
``` `gradlew clean build --debug` 性能下降时。此日志重复(可能是错误的线索)

2021-04-20T13:21:47.037+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Couldn't load Resource hibernate-generator-params-{0}.xml
2021-04-20T13:21:47.038+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource xdoclet/modules/hibernate/resources/hibernate-properties.xdt loaded from ant loader
2021-04-20T13:21:47.038+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Couldn't load Resource hibernate-properties.xml
2021-04-20T13:21:47.038+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Couldn't load Resource hibernate-properties-{0}.xml
2021-04-20T13:21:47.038+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource xdoclet/modules/hibernate/resources/hibernate-subclass.xdt loaded from ant loader
2021-04-20T13:21:47.038+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource xdoclet/modules/hibernate/resources/hibernate-joined-subclass.xdt loaded from ant loader
2021-04-20T13:21:47.038+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource xdoclet/modules/hibernate/resources/hibernate-query.xdt loaded from ant loader
2021-04-20T13:21:47.039+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource xdoclet/modules/hibernate/resources/hibernate-query.xdt loaded from ant loader
2021-04-20T13:21:47.039+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource xdoclet/modules/hibernate/resources/hibernate-sql-query.xdt loaded from ant loader
2021-04-20T13:21:47.039+1200 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource xdoclet/modules/hibernate/resources/hibernate-sql-query.xdt loaded from ant loader

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题