Answers:
您可以使用build-helper添加新的源目录:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/generated</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
plugin
元素/project/build/plugins
在/project/build/pluginManagement/plugins
m2e connector for build-helper-maven-plugin
要从eclipse市场安装,以消除pom.xml中的错误
'build.plugins.plugin.version' for org.codehaus.mojo:build-helper-maven-plugin is missing
需要在<plugin>
标签中添加<version>1.12</version>
我天真地这样做:
<build>
<finalName>osmwse</finalName>
<sourceDirectory>src/main/java, src/interfaces, src/services</sourceDirectory>
</build>
这对我有用
<build>
<sourceDirectory>.</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/main2/java/**/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
sourceDirectory
-可能是附加插件sources
-作为源文件的根。在您的解决方案中,maven-compiler-plugin
是唯一了解这些实际根源的插件。
要使其在intelliJ中工作,您还可以添加
<generatedSourcesDirectory>src/main/generated</generatedSourcesDirectory>
Maven编译器插件
通过定义资源标签,这也适用于maven。您可以随意命名src文件夹名称。
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.java</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/generated</directory>
<includes>
<include>**/*.java</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
Resources are not (usually) code. They are not compiled
这适用于maven 3.5.4,现在Intellij Idea将此代码作为源:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<generatedSourcesDirectory>src/main/generated</generatedSourcesDirectory>
</configuration>
</plugin>
从帖子中使用了build-helper-maven-plugin-并更新src / main / generated。而且mvn clean compile可在我的../common/src/main/java或../common上运行,因此保留后者。然后,是的,如David Phillips所述,确认IntelliJ IDEA(版本10.5.2)的编译级别失败。问题是IDEA没有将另一个源根目录添加到项目中。手动添加可以解决该问题。不好编辑项目中的任何内容都应该来自Maven,而不是直接编辑IDEA的项目选项。但是我将能够使用它,直到他们直接支持build-helper-maven-plugin,以便它将自动添加源。
然后需要另一个解决方法来使此工作正常进行。自从每次pom更改之后IDEA每次重新导入maven设置后,我都会将新添加的源保存在模块中,但是丢失了它的“源文件夹”选择并且没有用。因此,对于IDEA-需要设置一次:
现在,将这些文件夹保留在导入上也不是世界上的最佳做法,但是,请尝试一下。
在配置中,您可以使用<compileSourceRoots>
。
oal: org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-cli)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<basedir default-value="${basedir}"/>
<buildDirectory default-value="${project.build.directory}"/>
<compilePath default-value="${project.compileClasspathElements}"/>
<compileSourceRoots default-value="${project.compileSourceRoots}"/>
<compilerId default-value="javac">${maven.compiler.compilerId}</compilerId>
<compilerReuseStrategy default-value="${reuseCreated}">${maven.compiler.compilerReuseStrategy}</compilerReuseStrategy>
<compilerVersion>${maven.compiler.compilerVersion}</compilerVersion>
<debug default-value="true">${maven.compiler.debug}</debug>
<debuglevel>${maven.compiler.debuglevel}</debuglevel>
<encoding default-value="${project.build.sourceEncoding}">${encoding}</encoding>
<executable>${maven.compiler.executable}</executable>
<failOnError default-value="true">${maven.compiler.failOnError}</failOnError>
<failOnWarning default-value="false">${maven.compiler.failOnWarning}</failOnWarning>
<forceJavacCompilerUse default-value="false">${maven.compiler.forceJavacCompilerUse}</forceJavacCompilerUse>
<fork default-value="false">${maven.compiler.fork}</fork>
<generatedSourcesDirectory default-value="${project.build.directory}/generated-sources/annotations"/>
<maxmem>${maven.compiler.maxmem}</maxmem>
<meminitial>${maven.compiler.meminitial}</meminitial>
<mojoExecution default-value="${mojoExecution}"/>
<optimize default-value="false">${maven.compiler.optimize}</optimize>
<outputDirectory default-value="${project.build.outputDirectory}"/>
<parameters default-value="false">${maven.compiler.parameters}</parameters>
<project default-value="${project}"/>
<projectArtifact default-value="${project.artifact}"/>
<release>${maven.compiler.release}</release>
<session default-value="${session}"/>
<showDeprecation default-value="false">${maven.compiler.showDeprecation}</showDeprecation>
<showWarnings default-value="false">${maven.compiler.showWarnings}</showWarnings>
<skipMain>${maven.main.skip}</skipMain>
<skipMultiThreadWarning default-value="false">${maven.compiler.skipMultiThreadWarning}</skipMultiThreadWarning>
<source default-value="1.6">${maven.compiler.source}</source>
<staleMillis default-value="0">${lastModGranularityMs}</staleMillis>
<target default-value="1.6">${maven.compiler.target}</target>
<useIncrementalCompilation default-value="true">${maven.compiler.useIncrementalCompilation}</useIncrementalCompilation>
<verbose default-value="false">${maven.compiler.verbose}</verbose>
</configuration>
这些是可用于3.8.1版本的编译器插件的所有配置。不同的版本具有不同的配置,可以通过-X
在常规mvn命令之后运行代码来找到不同的配置。喜欢
mvn clean install -X
mvn compiler:compile -X
并使用ID或目标或插件名称进行搜索。这也可能对其他插件有所帮助。Eclipse,intelliJ可能不会显示所有配置作为建议。