gpt4 book ai didi

maven - Maven 中 build->sourceDirectory 的隐式赋值

转载 作者:行者123 更新时间:2023-12-04 02:32:40 26 4
gpt4 key购买 nike

如果 pom有一个 <build>标签但没有 <sourceDirectory>在其中显式设置,Maven 是否查看是否有 src源代码在根目录?我问这个是因为我在我的项目中继承的一些 poms 确实有源代码,有些没有 <sourceDirectory> .仅当实际源目录不是 src 时才需要显式设置该值吗? (例如 src/java)?

这是一个这样的 pom 的构建定义示例(注意,这是 pom 层次结构中的一个子 pom):

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Internal-Build-num>1.0-mybuild-SNAPSHOT</Internal-Build-num>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

这是 build superpom 部分:

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>1.0-alpha-7</version>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<!-- Version numbering -->
<plugin>
<artifactId>maven-scm-plugin</artifactId>
<configuration>
<!-- TAG format -->
<tag>${project.artifactId}-${project.version}</tag>
<pushChanges>false</pushChanges>
</configuration>
</plugin>

<!-- Version numbering -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<configuration>
<updateDependencies>true</updateDependencies>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
</plugins>

</build>

最佳答案

Maven 是关于 Convention over Configuration ,所以是的,您只需要在默认情况下指定 sourceDirectory 。 java 源代码的默认位置是:
源/主/java

阅读默认项目配置:Introduction to the Standard Directory Layout

关于maven - Maven 中 build->sourceDirectory 的隐式赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21293894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com