无法将 Intellij 与生成的源文件夹一起使用 [英] Unable to use Intellij with a generated sources folder

查看:27
本文介绍了无法将 Intellij 与生成的源文件夹一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关问题如何配置 IntelliJ IDEA 和/或 Maven 使用 jaxb2-maven-plugin 生成的 Java 源代码自动添加目录?

我有一个自定义插件,可以在 target/generated-sources 下生成源代码(注意这里没有工具名).所以我得到了像 target/generated-sources/com/mycompany... 等来源.

I have a custom plugin that generates sources under target/generated-sources (Note no toolname here). So I get sources like target/generated-sources/com/mycompany...etc.

这种格式根本无法更改,因此我可以将 Intellij 配置为将其添加为源文件夹.截至目前,我可以看到 Intellij 已添加 target/generated-sources/com 作为源文件夹.

This format cannot be changed at all, so will I be able to configure Intellij into adding it as a source folder. As of now, I can see that Intellij has added target/generated-sources/com as the source folder.

请注意,我没有配置插件的选项!

Please note that I do not have the option of configuring the plugin !

更新 1:我不同意我必须将生成的源放在工具名称文件夹下的事实.这可能是一个很好的约定,但如果我只有一个生成器,我就不需要把它放在那里吗?同样,在我的 pom.xml 中,我有一个 resources 部分,它清楚地表明 target/generated-sources 应该被视为源文件夹.这在 Eclipse 中工作得非常好,所以我不知道为什么 Intellij 不尊重我的设置.

UPDATE 1: I do not agree with the fact that I MUST put my generated sources under a tool name folder. It may be a good convention, but if I have only one generator there is no need for me to put it there? Again, in my pom.xml I have a resources section which clearly indicates that target/generated-sources should be treated as a source folder. This works perfectly fine in Eclipse so I have no idea why Intellij would not respect my settings.

TL;DR -> 当我将 target/generated-sources 放在 pom.xml 的资源部分时,为什么 Intellij 过于热情地添加 target/generated-sources/com 到类路径?

TL;DR -> When I put target/generated-sources in the resource section of pom.xml why is Intellij overzealous to add target/generated-sources/com to the classpath?

推荐答案

您可以更改项目结构以将该文件夹添加为源"目录.

You can just change the project structure to add that folder as a "source" directory.

项目结构 → 模块 → 单击 generated-sources 文件夹并将其设为 sources 文件夹.

Project Structure → Modules → Click the generated-sources folder and make it a sources folder.

或者:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <id>test</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${basedir}/target/generated-sources</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

这篇关于无法将 Intellij 与生成的源文件夹一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆