gpt4 book ai didi

gradle - 如何通过gradle为AspectJ和spring-aspects在STS(eclipse)中设置.classpath

转载 作者:行者123 更新时间:2023-12-03 04:04:12 30 4
gpt4 key购买 nike

我有一个项目使用@Configurable从Spring方面将@Configurable的编译时间编织到我的类中。
我使用Spring Tool Suite 3.7.0,并且如果我使用gradle任务来构建和启动我的应用程序,那么一切都会运行。 (感谢插件:https://github.com/eveoh/gradle-aspectj)。

现在,我还想使用AspectJ Eclipse特性。通过将项目变成AspectJ并添加spring-aspects.jar作为AspectJ inpath,我手动运行了此程序。
我也想通过gradle做到这一点。
可以通过以下方式将项目转变为AspectJ性质:

eclipse {
project {
buildCommand('org.eclipse.ajdt.core.ajbuilder')
natures += 'org.eclipse.ajdt.ui.ajnature'
}

如何配置gradle,使其同时执行“将spring-aspects.jar添加为我的路径”步骤?

当我比较.classpath文件时,区别是:
<classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.web.container">
<attributes>
<attribute name="org.eclipse.ajdt.inpath.restriction" value="spring-aspects-4.1.7.RELEASE.jar"/>
<attribute name="org.eclipse.ajdt.inpath" value="org.eclipse.ajdt.inpath"/>
</attributes>
</classpathentry>

<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>

(classpathentry org.eclipse.jst.j2ee.internal.web.container已经存在,但是缺少属性)

那么如何将其添加到类路径中呢?我看过 examples正在像这样修改类路径:
eclipseClasspath {
withXml { xmlProvider ->
def classpath = xmlProvider.asNode()
def parser = new XmlParser()

...但是我总是在这里得到一个错误: could not find method whenConfigured() for arguments [build_52wic5gr82z6rcs33lo3ix1lk$_run_closure7_closure12_closure13@73914b82] on org.gradle.plugins.ide.eclipse.model.EclipseClasspath_Decorated@6ca18169.如何解决这个错误?
这是配置AspectJ inpath以手动适应.classpath的正确方法吗?

最佳答案

最后,我找到了一个解决方案,可能会对其他人有所帮助。
要创建命名的.classpath片段,只需在build.gradle中添加以下内容

eclipse {
classpath {
file {
withXml {

def xmlparser = new XmlParser()

def node = it.asNode()
node.findAll{it['@path'] == 'org.eclipse.jst.j2ee.internal.web.container'}.each {
println it;
def attributes = xmlparser.createNode(it, 'attributes', [:])
xmlparser.createNode(attributes, 'attribute', [name: 'org.eclipse.ajdt.inpath.restriction', value: 'spring-aspects-4.1.7.RELEASE.jar']);
xmlparser.createNode(attributes, 'attribute', [name: 'org.eclipse.ajdt.inpath', value: 'org.eclipse.ajdt.inpath']);
...

关于gradle - 如何通过gradle为AspectJ和spring-aspects在STS(eclipse)中设置.classpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31653160/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com