无法将Intellij与生成的源文件夹一起使用

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

我有一个自定义插件,可以在target/generated-sourcestarget/generated-sources (注意这里没有toolname)。 所以我得到像target/generated-sources/com/mycompanytarget/generated-sources/com/mycompany

这种格式根本不能改变,所以我可以configurationIntellij添加它作为源文件夹。 截至目前,我可以看到Intellij已经将target/generated-sources/com为源文件夹。

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

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

TL; DR – >当我把target/generated-sources放在pom.xml的资源部分,为什么Intellij过热将target/generated-sources/com到类path中?

您只需更改项目结构即可将该文件夹添加为“源”目录。

项目结构→模块→单击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> 

修复

转到项目结构模块源文件夹 ,findtarget/generated-sources/antlr4/com/mycompany – 单击编辑属性 ,并将包前缀设置为com.mycompany

这正是我们为什么可以在源代码上设置Package前缀的原因。


不同但相关的问题在这里

使用gradle时,只要刷新gradle设置,项目设置就会被清除。 相反,您需要在build.gradle中添加以下行(或类似行),我使用kotlin:

 sourceSets { main { java { srcDir "${buildDir.absolutePath}/generated/source/kapt/main" } } } 

谁写这个插件谁搞砸了大的时间。 这不是做到这一点!

任何解决方法将是一个巨大的黑客,使插件开发人员意识到他的错误。

对不起,这是唯一要做的事情。


确定这里有一个黑客,直接在你的插件执行后,使用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> 

在这个例子中, toolname应该replace为唯一标识创build代码的插件的任何东西, com代表创build的包的根。 如果你有多个包根,你可能需要多个<move>任务。

但是,如果插件添加文件夹作为源文件夹,那么你拧了。

也许你可以添加一个步骤到移动文件夹的生成源代码阶段?

我使用Maven(SpringBoot应用程序)为此,解决scheme

  1. 右键单击项目文件夹
  2. selectMaven
  3. select生成源和更新文件夹

然后,Intellij自动将生成的源导入到项目中。