[英]Filter class files from compiled sourcesets to be added in a JAR in Gradle/Groovy
I'm trying to include the compiled .class files from Project1 into the jar for Project2 since my project structure requires it to be done. 我正在尝试将Project1的已编译.class文件包含到Project2的jar中,因为我的项目结构要求完成该工作。 For that, in the build.gradle for Project2 , I write : 为此,在Project2的build.gradle中,我写道:
jar {
from project(':Project1').sourceSets.main.output.classesDir
}
Which successfully does what I had to do. 哪个成功完成了我必须做的事情。 But, I now want to filter some of the classes that are added based on path and/or some pattern. 但是,我现在想过滤一些基于路径和/或某种模式添加的类。 For example, to include only delegate files, I tried this : 例如,仅包括委托文件,我尝试了以下方法:
jar {
from project(':Project1').sourceSets.main.output.classesDir {
include '**/*Delegate*.class'
}
}
But unfortunately it doesn't work. 但不幸的是,它不起作用。 Is there a way to achieve this in Gradle/Groovy? 有没有办法在Gradle / Groovy中实现这一目标?
Using Gradle 2.12, the following works for me (this is build.gradle
for Project 2): 使用Gradle 2.12,以下对我build.gradle
(这是Project 2的build.gradle
):
task myBuild(type: Jar) {
baseName "myjar"
from project(':Project1').sourceSets.main.output.classesDir,
{ include "**/*Delegate*.*" }
}
From the doc for Jar.from , note that it takes 2 arguments (hence, the comma is used). 从Jar.from的文档中 ,请注意,它需要2个参数(因此,使用逗号)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.