Delombok的源代码具有添加的jar依赖项

时间:2019-07-05 14:26:56

标签: java gradle lombok

我无法释放Java源代码,这显然是由于该项目具有jar依赖项,我也不明白为什么。必须将两个jar文件提交到存储库才能进行标记,然后通过添加行dependencies将它们添加到build.gradle文件的compile files('myproj1.jar')节点的项目中。因此,build.gradle文件的相关部分如下所示:

dependencies {
     compile files('myproj1.jar')
     compile files('myproj2.jar')

     .....
}

运行delombok任务时,出现以下错误:

Execution failed for task ':delombok'.
> taskdef class lombok.delombok.ant.Tasks$Delombok cannot be found
   using the classloader AntClassLoader[/path/to/repo/myproj1.jar:/path/to/repo/myproj2.jar]

为什么delombok任务会使用jar文件中的AntClassLoader

我已经尝试过此post的delombok'ing代码

这是我的build.gradle文件中的任务

def srcJava = 'src/main/java'
def srcDelomboked = 'build/src-delomboked'

task delombok {
    // delombok task may depend on other projects already being compiled
    dependsOn configurations.compile.getTaskDependencyFromProjectDependency(true, "compileJava")

    // Set up incremental build, must be made in the configuration phase (not doLast)
    inputs.files file(srcJava)
    outputs.dir file(srcDelomboked)

    doLast {
        FileCollection collection = files(configurations.compile)
        FileCollection sumTree = collection + fileTree(dir: 'bin')

        ant.taskdef(name: 'delombok', classname: 'lombok.delombok.ant.Tasks$Delombok', classpath: configurations.compile.asPath)
        ant.delombok(from:srcJava, to:srcDelomboked, classpath: sumTree.asPath)
    }
}

我希望能够在构建过程中释放Java源代码,以便在编译项目时不依赖Lombok。

1 个答案:

答案 0 :(得分:1)

因此,在继续尝试错误之后,我有了一个可行的实现。要回答我自己的问题,该问题与其他Jar文件无关。相反,当gradle运行 <dependency> <groupId>com.google.appengine</groupId> <artifactId>appengine-api-1.0-sdk</artifactId> <version>1.9.69</version> </dependency> <dependency> <groupId>org.httprpc</groupId> <artifactId>httprpc</artifactId> <version>6.3.3</version> </dependency> <!-- [START servlet] --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <type>jar</type> <scope>provided</scope> </dependency> <!-- [END servlet] --> <dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client-appengine</artifactId> <version>1.7.0-beta</version> </dependency> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>com.google.apis</groupId> <artifactId>google-api-services-urlshortener</artifactId> <version>v1-rev57-1.25.0</version> </dependency> <dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client</artifactId> <version>1.8.0-beta</version> </dependency> <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> <dependency> <groupId>com.healthmarketscience.sqlbuilder</groupId> <artifactId>sqlbuilder</artifactId> <version>3.0.0</version> </dependency> <!-- [START_EXCLUDE] --> <!-- Test Dependencies --> <dependency> <groupId>com.google.appengine</groupId> <artifactId>appengine-testing</artifactId> <version>1.9.69</version> <scope>test</scope> </dependency> <dependency> <groupId>com.google.firebase</groupId> <artifactId>firebase-admin</artifactId> <version>6.8.1</version> </dependency> <dependency> <groupId>com.google.appengine</groupId> <artifactId>appengine-api-stubs</artifactId> <version>1.9.69</version> <scope>test</scope> </dependency> <dependency> <groupId>com.google.appengine</groupId> <artifactId>appengine-tools-sdk</artifactId> <version>1.9.69</version> <scope>test</scope> </dependency> <dependency> <groupId>com.google.truth</groupId> <artifactId>truth</artifactId> <version>0.42</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13-beta-1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>2.23.4</version> <scope>test</scope> </dependency> <dependency> <!-- Only used locally --> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.42</version> </dependency> <dependency> <groupId>com.google.cloud.sql</groupId> <artifactId>mysql-socket-factory</artifactId> <version>1.0.12</version> </dependency> <!-- [END_EXCLUDE] --> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20160810</version> <type>jar</type> </dependency> </dependencies> 任务时,lombok jar中的类不在delombok的类路径中(即org.gradle.api.AntBuilder任务),因此它没有在任何地方都引用ant(目前似乎很明显,但当时还没有)。

到目前为止,解决方案是在lombok.delombok.ant.Tasks$Delombok

中添加这些引用

结合此post和此post的代码片段,您可以使用以下方法:

configurations.compile

希望这有助于其他需要分发代码的人。