- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在努力让 Gradle 根据 this blog post 生成一个 IntelliJ WAR 工件定义作为“想法”任务的一部分。 .尽管我的代码很脏,但到目前为止,这已经很成功了,所以我正在尝试清理它。
就我而言, war 任务应该包含在 IntelliJ 中创建必要标签所需的所有信息。例如,给定一个 Gradle Project 对象,比如 gradleProject,我可以执行以下操作:
def artifactManager = project.component.find { it.@name == 'ArtifactManager' } as Node
if (artifactManager) {
Node artifact = artifactManager.artifact.find { it.@type == 'exploded-war' }
if (artifact) {
artifactManager.remove(artifact)
}
} else {
artifactManager = project.appendNode('component', [name: 'ArtifactManager']);
}
def builder = new NodeBuilder();
def artifact = builder.artifact(type: 'exploded-war', name: "${gradleProject.name} exploded war") {
'output-path'("${gradleProject.buildDir}/${gradleProject.name}-exploded.war")
root(id: 'root') {
element(id: 'directory', name: 'WEB-INF') {
// copy web.xml
element(id: 'file-copy', path: gradleProject.war.webXml)
Set<String> excludeJars = [] as Set
element(id: 'directory', name: 'classes') {
// copy classes
element(id: 'module-output', name: gradleProject.name)
// copy depending projects module output (classes)
gradleProject.configurations.runtime.allDependencies.each {
if (it.hasProperty('dependencyProject')) { // TODO: make it functional?!?
if (it.dependencyProject.hasProperty('jar'))
excludeJars.add(it.dependencyProject.jar.archiveName)
element(id: 'module-output', name: it.dependencyProject.name)
}
}
}
// copy dependency jars excluding possible existing module jars (not sure it's necessary)
element(id: 'directory', name: 'lib') {
// TODO: this should handle ALL kinds of dependencies
gradleProject.configurations.runtime.each {
if (!excludeJars.contains(it.name))
element(id: 'file-copy', path: it)
}
}
}
}
}
artifactManager.append artifact
war{
from project(':rest').file('resource/some.properties')
from project(':some_project').fileTree('some_folder')
metaInf {
from parent.file('build/config/website/' + environment + '/context.xml')
}
}
gradleProject.war.source.each { // ... create tags etc. }
最佳答案
我终于在 Gradle 文档的帮助下和一些反复试验弄明白了。我使用以下代码得到了想要的结果:
def artifactManager = project.component.find { it.@name == 'ArtifactManager' } as Node
if (artifactManager) {
Node artifact = artifactManager.artifact.find { it.@type == 'exploded-war' }
if (artifact) {
artifactManager.remove(artifact)
}
} else {
artifactManager = project.appendNode('component', [name: 'ArtifactManager']);
}
def builder = new NodeBuilder();
def artifact = builder.artifact(type: 'exploded-war', name: "${gradleProject.name} exploded war") {
'output-path'("${gradleProject.buildDir}/${gradleProject.name}-exploded.war")
root(id: 'root') {
println "Adding files to root"
gradleProject.war.rootSpec.children.each {
if (it.destPath.pathString.equals("")) {
add(builder, it, "")
}
}
println "Adding files to META-INF"
element(id: 'directory', name: 'META-INF') {
gradleProject.war.rootSpec.children.each {
if (it.destPath.pathString.equals("META-INF")) {
add(builder, it, "META-INF")
}
}
}
println "Adding files to WEB-INF"
element(id: 'directory', name: 'WEB-INF') {
element(id: 'file-copy', path: gradleProject.war.webXml)
gradleProject.war.rootSpec.children.each {
if (it.destPath.pathString.equals("WEB-INF")) {
add(builder, it, "WEB-INF")
}
}
Set<String> excludeJars = [] as Set
element(id: 'directory', name: 'classes') {
element(id: 'module-output', name: gradleProject.name)
gradleProject.configurations.runtime.allDependencies.each {
if (it.hasProperty('dependencyProject')) {
if (it.dependencyProject.hasProperty('jar'))
excludeJars.add(it.dependencyProject.jar.archiveName)
element(id: 'module-output', name: it.dependencyProject.name)
}
}
}
element(id: 'directory', name: 'lib') {
gradleProject.configurations.runtime.each {
if (!excludeJars.contains(it.name))
element(id: 'file-copy', path: it)
}
}
}
}
}
artifactManager.append artifact
add
函数定义为:
def add(NodeBuilder builder, Object s, String dest, String prefix = "") {
println(prefix + "current destination: [" + dest + "]")
if (s instanceof File) {
println(prefix + "-- file " + s.toString())
builder.element(id: 'file-copy', path: s)
} else if (s instanceof FileTree) {
println(prefix + "-- folder " + s.dir.toString())
builder.element(id: 'dir-copy', path: s.dir)
} else if (s instanceof CopySpecInternal) {
print(prefix + "-- copy spec " + s.toString() + " with destination path: [" + s.destPath.pathString + "]; ")
if (dest.equals(s.destPath.pathString)) {
println("destination matches current folder")
s.sourcePaths.each { path ->
add(builder, path, dest, prefix + " ")
}
s.children.each { child -> add(builder, child, dest, prefix + " ") }
} else {
println("")
if (s.destPath.segments != null && s.destPath.segments.length > 0 && s.destPath.segments[0].equals(dest)) {
String relDest = new RelativePath(false, Arrays.copyOfRange(s.destPath.segments, 1, s.destPath.segments.length)).pathString
builder.element(id: 'directory', name: relDest) {
s.sourcePaths.each { path ->
add(builder, path, relDest, prefix + " ")
}
s.children.each { child -> add(builder, child, relDest, prefix + " ") }
}
} else {
println(prefix + "!! destination path is not relative to [" + dest + "]: [" + s.destPath.pathString + "]")
}
}
} else println(prefix + "?? unknown " + s.toString())
}
war
进行了逆向工程任务属性并挖掘到要复制的文件树中。据我所知,这个任务并没有公开一个接口(interface)来做这种事情,所以我不得不求助于一个“hacky”的解决方案,这不是我最喜欢的。如果有人可以提供一些更简洁的代码,我会很高兴。
关于groovy - Gradle WAR 插件 : how to find destination for files to copy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21286176/
如何将 jQuery 代码转换为 React JS? 我有一个带有文本“复制”的按钮。当我单击它时,应将其文本更改为“已复制”并复制到剪贴板。复制后,几秒钟后我希望文本返回到“复制”。我相信以下功能将
在任何情况下我都想使用 NumPy 的 np.copy() 而不是 Python 的 copy.copy() 方法?据我所知,两者都创建浅拷贝,但 NumPy 仅限于数组。 NumPy 是否有任何性能
%python -m timeit -s "import copy" "x = (1, 2, 3)" "copy.deepcopy(x)" 100000 loops, best of 3: 10.1
我想制作一个列表的副本(字面意思是一个单独的克隆,与原始列表没有任何共享)。我使用了 copy.copy() 并创建了 2 个单独的列表,但为什么每个副本的元素似乎仍然共享? 这很难解释,请查看以下输
我不明白使用通配符时 COPY 命令的行为。 我在 C:\Source 中有一个文本文件叫 mpt*.asm我想把它复制到 C:\Dest .这是批处理脚本所需要的,我不能确定 mpt*.asm 的确
相关但不等同于:Golang: How to copy Context object without deriving 是否可以推导出 context.WithTimeout来自 context.Ba
您可以实现 Copy 特性来为类型提供复制语义而不是 move 语义。仅当其所有组成元素(产品类型的每个因素,或总和类型的每个变体的每个因素)也都是复制时,才能执行此操作。 这还允许您制作相当大的类型
我有一段代码,我需要确定编码值的类型,但我不知道它是字符串、无符号整数还是字符串的矢量。我想做以下几件事:。然而,来自弯曲板条箱的值不能实现复制,它在调用Decode_Bencode_Object之后
我需要复制一些对象,我读到 copy.copy 模块可以在 Python 上执行此操作。问题是,这些对象有一些属性是长数组。 那么这个方法效率高吗?由于性能在我所做的这项工作中很重要。 有更好的方法吗
我尝试高效地制作 lua 表的副本。我编写了以下运行良好的函数 copyTable()(见下文)。但我想我可以使用函数的“按值传递”机制获得更高效的东西。我做了一些测试来探索这个机制: functio
使用 pry 插件:pry-clipboard 当我输入“copy-history”来复制我历史的最后一行时,它实际上是在复制“copy-history”并粘贴“copy-history”。 我是不是
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve this
我不了解Kotlin中通过访问器处理字段和复制方法之间的区别。就像这样: 访问者示例: class Person(val name: String, var age: Int
如何从节点复制一些属性。例如。我只想从节点“Extn”复制“Srno”,“RollNo”,“right”。
我有以下两个 XSL 转换,我希望将它们链接到一个 XSL 文件中。 第一次转换: 第二个转换(使用第一个转换的输出作为输入): 我的目标是从 WSDL
我是 Vertica DB 的新手,之前使用过 Mysql。我想在 vertica 表中插入唯一记录,但 vertica 在插入时不支持唯一约束。我通过 COPY 查询在表中插入记录。所以我无法在插入
std::copy 与执行策略参数之间是否存在正式关系?无论是在实践中还是在标准中。 例如,会不会只是这样, namespace std{ template It copy(std::
我用 root 运行了以下命令来备份同一主机上的文件夹:cp -r master 主备 size of master : 76GB size of master-backup : 71GB 知道为什么
我遇到过一段代码,乍一看似乎毫无意义。但我意识到这可能会产生一些我不知道的未知含义,因为 Python 不是我最熟悉的语言。 import copy node = copy.copy(node) 阅读
我正在设计一个基类,我希望它为 copy.copy 定义基本行为。此行为包括在控制台中打印警告,然后复制实例,就好像它没有 __copy__ 一样。属性。 当定义一个空白时Foo类并复制它的一个实例,
我是一名优秀的程序员,十分优秀!