【问题标题】:How to retrieve the current dependencies in a Grails 3.2 script如何在 Grails 3.2 脚本中检索当前依赖项
【发布时间】:2017-09-29 22:21:21
【问题描述】:

上下文

我使用下一个命令创建了一个 Grails 3.2.11 脚本:

grails create-script script-test

以上命令生成文件:script-test.groovy

然后,我需要验证当前 grails 项目中是否存在 jar 文件依赖项。

在 Grails 2.4 中,您可以通过 grailsSettings.runtimeDependencies 调用来做到这一点:

def verifyJarDependency(String dependencyName) {

    //Gets all Grails Application dependencies.
    def dependenciesInstance = grailsSettings.runtimeDependencies

    //Defines the result variable
    def result = false

    //Adds references to all classes used in Grails Application.
    dependenciesInstance?.each { dependencyFile ->

        //Gets the file name
        String fileName = dependencyFile.name

        //Verifies if the actual file contains the Dependency file string
        if (fileName.contains(dependencyName)) {

            //There is a Jar file with the Dependency string.
            println "The Dependency file found is: $dependencyFile"
            result = true
        }
    }

    //If there is no Dependency jar file it returns false.
    return result
}

例如,如果您在 grails 2.4 脚本文件中执行下一段代码:

target(buildPlugin: "Retrieves all the jar files which this instance is using") {

    //Gets all Grails Application dependencies.
    def dependenciesInstance = grailsSettings.runtimeDependencies

    dependenciesInstance?.each { dependencyFile ->

        //There is a Jar file with the Dependency string.
        println dependencyFile
    }
}

setDefaultTarget(buildPlugin)

你会得到如下输出:

/home/username/.sdkman/candidates/grails/2.4.3/lib/org.grails/grails-datastore-simple/jars/grails-datastore-simple-3.1.2.RELEASE.jar
/home/username/.sdkman/candidates/grails/2.4.3/lib/org.grails/grails-datastore-gorm/jars/grails-datastore-gorm-3.1.2.RELEASE.jar
/home/username/.sdkman/candidates/grails/2.4.3/dist/grails-plugin-converters-2.4.3.jar
/home/username/.sdkman/candidates/grails/2.4.3/dist/grails-plugin-mimetypes-2.4.3.jar
/home/username/.sdkman/candidates/grails/2.4.3/lib/com.h2database/h2/jars/h2-1.3.176.jar
/home/username/.sdkman/candidates/grails/2.4.3/lib/log4j/log4j/jars/log4j-1.2.17.jar
/home/username/.sdkman/candidates/grails/2.4.3/dist/grails-resources-2.4.3.jar

此信息稍后将用于 Proguard 以混淆 jar 文件。

问题

如何在自定义脚本中检索当前 Grails 3.2 项目依赖项?

【问题讨论】:

    标签: grails grails3 grails-3.2


    【解决方案1】:

    您可以在自定义脚本中执行“gradle dependencies”:

    description "Project dependencies", "grails list-dependencies"
    println gradle.dependencies()
    

    并解析输出

    【讨论】:

    • 首先,感谢您的回答。关于它,这是您可以在 Grails 脚本文件中调用任何 Gradle 任务的方式,但是,它只为您提供依赖项名称而没有文件名。也许我的问题需要澄清一下,因为我需要 jars 文件名及其路径。因为该信息将被另一个使用 Proguard 混淆 jar 文件的脚本使用。我更新了问题以显示我需要的信息。
    • 在这种情况下,您可以扫描工作目录 grails.util.BuildSettings.TARGET_DIR 以查找 .war 文件并扫描所有 jars
    猜你喜欢
    • 2017-09-12
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多