Kan*_*ath 71 java maven-2 intellij-idea
相关问题 如何配置IntelliJ IDEA和/或Maven自动添加使用jaxb2-maven-plugin生成的Java源代码的目录?
我有一个自定义插件,可以生成源代码target/generated-sources
(注意这里没有工具名).所以我得到像target/generated-sources/com/mycompany
......等来源.
这种格式根本无法更改,因此我可以将Intellij配置为将其添加为源文件夹.截至目前,我可以看到Intellij已添加target/generated-sources/com
为源文件夹.
请注意,我没有配置插件的选项!
更新1:我不同意我必须将生成的源放在工具名称文件夹下的事实.这可能是一个很好的约定,但如果我只有一台发电机,我就没有必要把它放在那里?同样,在我的pom.xml中,我有一个resources
部分清楚地表明target/generated-sources
应该将其视为源文件夹.这在Eclipse中运行得非常好,所以我不知道为什么Intellij不尊重我的设置.
TL; DR - >当我放入target/generated-sources
资源部分时pom.xml
为什么Intellij过分热衷于添加target/generated-sources/com
到类路径?
DaS*_*aun 115
您只需更改项目结构即可将该文件夹添加为"源"目录.
项目结构→模块→单击generated-sources
文件夹并将其sources
设为文件夹.
要么:
<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>
Run Code Online (Sandbox Code Playgroud)
Meh*_*ğlu 39
我正在使用Maven(SpringBoot应用程序)解决方案是:
然后,Intellij自动将生成的源导入项目.
zhy*_*ywu 18
使用gradle时,只要刷新平移设置,项目设置就会被清除.相反,你需要在build.gradle中添加以下行(或类似的),我正在使用kotlin:
sourceSets {
main {
java {
srcDir "${buildDir.absolutePath}/generated/source/kapt/main"
}
}
}
Run Code Online (Sandbox Code Playgroud)
Vla*_*čík 15
转到项目结构 - 模块 - 源文件夹,然后找到target/generated-sources/antlr4/com/mycompany
- 单击编辑属性并将包前缀设置为com.mycompany
.
这正是我们可以在源目录上设置包前缀的原因.
这里有不同但相关的问题
小智 6
对于仍在努力修复 IntelliJ 未拾取的生成源的人来说,
原因之一可能是生成的文件太大而无法加载,然后您需要将以下行放入“自定义 IntelliJ IDEA 属性”(在菜单帮助下)
idea.max.intellisense.filesize=7500
Run Code Online (Sandbox Code Playgroud)
写那个插件的人搞砸了。这不是这样做的方法!
任何解决方法都将是一个巨大的黑客,让插件开发人员意识到他的错误。
对不起,这是唯一的办法。
好的,这里有一个 hack,直接在你的插件执行后,使用 antrun 插件将目录移动到其他地方:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>process-sources</phase>
<configuration>
<target>
<move todir="${project.build.directory}/generated-sources/toolname/com"
overwrite="true">
<fileset dir="${project.build.directory}/generated-sources/com"/>
</move>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在此示例中,toolname
应替换为唯一标识创建代码的插件并com
代表创建的包的根的任何内容。如果您有多个包根,您可能需要多个<move>
任务。
但是如果插件将文件夹添加为源文件夹,那么你就完蛋了。
归档时间: |
|
查看次数: |
85191 次 |
最近记录: |