简体   繁体   English

迁移Ant Gradle - Eclipse中的类路径和Buildpath问题

[英]Migration Ant Gradle - Classpath and Buildpath issues in Eclipse

Current situation: I am migrating a build system from Ant to Gradle. 当前情况:我正在将构建系统从Ant迁移到Gradle。 Currently I'm facing an issue with the classpath and buildpath. 目前我遇到了类路径和构建路径的问题。 Here is the current Ant compile target definition: 这是当前的Ant编译目标定义:

    <target name="compile">
        <mkdir dir="${build.compile.target}/classes" />
        <javac srcdir="${src}" destdir="${build.compile.target}/classes">
            <classpath>
                <fileset dir="${build.war}/WEB-INF/lib">
                    <include name="**/*.jar" />
                </fileset>
                <pathelement location="${build.war}/WEB-INF/classes" />
            </classpath>
        </javac>
    </target>

The developers usually execute the following setup-local target to build the war files, etc. 开发人员通常执行以下setup-local目标来构建war文件等。

<target name="setup-local" depends="clean">
    <antcall target="copy_webapp" />
    <antcall target="compile" />

The copy_webapp target is copying .jar and .class files from a directory into the ${build.war} directory. copy_webapp目标是将目录中的.jar和.class文件复制到$ {build.war}目录中。 Unfortunately this copy target is really needed as it makes relevant modifications to the files (it's merging files from two directories into one, does overwriting and file modifications. It's legacy code without any comments. I really don't want to do research on it and find out why things are how they are) 不幸的是,这个拷贝目标确实是需要的,因为它对文件进行了相关修改(它将文件从两个目录合并为一个,覆盖和文件修改。它是遗留代码,没有任何注释。我真的不想对它进行研究和找出为什么它们是这样的)

The problem for me: In the classpath there is a reference on files which do only exist when the copy_webapp target is executed beforehand. 对我来说问题是:在类路径中有一个文件引用,它只在事先执行copy_webapp目标时才存在。 Fair enough - This works if I always execute the setup-local target only. 足够公平 - 如果我总是只执行setup-local目标,这是有效的。

Now after migrating to Gradle and importing the project to Eclipse, I get thousands of errors in my .java files, saying the imports cannot be resolved. 现在迁移到Gradle并将项目导入Eclipse后,我的.java文件中出现了数千个错误,说无法解析导入。 Well, of course not. 好吧,当然不是。 In the buildpath are files (fe "${build.war}/path/to/jar") that are not existing. 在构建路径中是不存在的文件(fe“$ {build.war} / path / to / jar”)。

I don't know how to solve these errors. 我不知道如何解决这些错误。 Do I need to restructure my classpath so that there is no dependency on the copy_webapp target before? 我是否需要重构我的类路径,以便之前不依赖于copy_webapp目标? Or can I modify the buildpath somehow (with Gradle) that it first has to resolve the copy_webapp target before? 或者我可以以某种方式(使用Gradle)修改构建路径,它首先必须解析copy_webapp目标吗?

Given the information it's hard to get at the root of your problem. 鉴于这些信息很难找到问题的根源。

One option is to create a "staging" directory for the Eclipse project when you have a Gradle task that is generating a complex directory structure and/or intermediate output needed by Eclipse deploy your project. 当您有一个Gradle任务生成Eclipse部署项目所需的复杂目录结构和/或中间输出时,可以选择为Eclipse项目创建一个“staging”目录。

The way I tackle this is by creating a sub-task that is run when calling gradle eclipse . 我解决这个问题的方法是创建一个在调用gradle eclipse时运行的子任务。 Add the line it.dependsOn eclipse in the configuration of the task. 在任务配置中添加it.dependsOn eclipse行。 The output of this task would go into build/eclipse/TaskName or some descriptive location in the build/ dir. 此任务的输出将进入build/eclipse/TaskNamebuild/ dir中的某个描述性位置。 The classpath references should then be updated to point to the output directory location under your build/ dir. 然后应该更新类路径引用以指向build/ dir下的输出目录位置。

Also, you might have to post-process the classpath entries that the eclipse task is using to generate the project classpath so they correctly reference task output location. 此外,您可能必须对eclipse任务正在使用的类路径条目进行后处理,以生成项目类路径,以便它们正确引用任务输出位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM