简体   繁体   English

如何在java中解析build.gradle文件?

[英]How to parse a build.gradle file in java?

I need to parse the gradle build.gradle file in Java and list out all its dependencies(as List of Group:Artifact:Version) mentioned under dependencies block.我需要解析 Java 中的 gradle build.gradle 文件,并列出其所有依赖项(如 List of Group:Artifact:Version )在依赖项块下提到。

What would be the best possible solution for this?什么是最好的解决方案?

build.gradle like below, build.gradle 如下所示,

apply plugin: 'java-library'

repositories {
    jcenter()
}

dependencies {
    compileOnly group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
    compile group: 'com.google.code.findbugs', name: 'annotations' , version: '3.0.0'
    compile "com.google.code.gson:gson:2.8.5"
    compile "org.owasp:dependency-check-gradle:4.0.1"
    compile 'org.apache.httpcomponents:httpclient:4.5.7'
    api 'org.apache.commons:commons-math3:3.6.1'
    implementation 'com.google.guava:guava:21.0'
    testImplementation 'junit:junit:4.12'
}
  1. Create a custom gradle task to list all dependencies into a file.创建自定义 gradle 任务以将所有依赖项列出到文件中。
  2. Hook this task to the very beginning of build process.将此任务挂接到构建过程的最开始。
  3. Read that file from java从java读取该文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM