1

我有一个项目使用编译时将@Configurable 从spring-aspects 编织到我的类中,使用@Configurable。如果我使用 gradle 任务来构建和启动我的应用程序,我使用 Spring Tool Suite 3.7.0 并运行所有东西。(感谢插件: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 作为我的 inpath”步骤?

当我比较 .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"/>

(类路径入口 org.eclipse.jst.j2ee.internal.web.container 已经存在,但缺少属性)

那么如何将这个片段添加到类路径中呢?我见过像这样修改类路径的示例:

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 的正确方法吗?

4

1 回答 1

1

最后我找到了一个解决方案,也许对其他人有帮助。要创建命名的 .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']);
...
于 2015-07-30T13:11:44.390 回答