Maven2有哪些隐藏功能?

发布于 2024-07-08 23:45:26 字数 1455 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

枯叶蝶 2024-07-15 23:45:27

看看依赖关系:分析。

Take a look at dependency:analyze as well.

胡渣熟男 2024-07-15 23:45:27

有时,您的文件需要包含一些只能在构建时发现的值。 也许您有一个 Java 类,用于检查评估期是否已到,并将该期限定义为“编译此版本后三十天”。 您需要一种方法将当前日期或其他一些属性直接注入到构建中。

Maven 有一个很酷的隐藏功能,称为过滤(此处的文档 )。 通过过滤,您可以要求 Maven 在某些源文件中查找模式并用某些值替换它们,并且激活起来很容易:

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>

您可以将什么放入过滤器中? 任何环境变量、pom 文件中的大部分值以及有关 java 编译器的信息。 现在,如果您更改 Maven 中的版本号,则不必再查找whatever.properties 文件并在那里更新您的版本。 你只需在 Maven 中修改它就可以了。

Sometimes you have a file that needs to contain some value that can only be discovered at build time. Maybe you have a Java class that checks to see if the evaluation period is up, and you define that period as "thirty days after this build was compiled". You need a way to inject the current date, or some other property, directly into the build.

Maven has a cool, hidden feature called filtering (Documentation here). With filtering, you can ask Maven to look for patterns in certain source files and replace them with some value, and it's as easy to activate as this:

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>

What can you stick into the filter? Any environment variable, most of the values in the pom file, and information about the java compiler. Now If you change your version number in Maven, you don't have to go find your whatever.properties file and update your version there, too. You can just modify it in Maven and you're done.

终止放荡 2024-07-15 23:45:27

使用 maven-dependency-plugin 可以解决依赖冲突和循环依赖问题。

添加到您的 pom.xml:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
</plugin>

然后运行 ​​mvn dependency:resolvemvn dependency:build-classpath 来测试它。

有关依赖插件的更多信息:
http://maven.apache.org/plugins/maven-dependency-插件/howto.html

With maven-dependency-plugin it's possible to resolve dependency conflicts and cyclic dependency problems.

Add to your pom.xml:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
</plugin>

Then run mvn dependency:resolve or mvn dependency:build-classpath to test it.

More about the dependency plugin:
http://maven.apache.org/plugins/maven-dependency-plugin/howto.html

百思不得你姐 2024-07-15 23:45:27
  1. 项目继承
  2. 项目聚合程序
  3. 集:程序集
  4. 报告(findbugs、checkstyle、clover、pmd等)
  1. project inheritance
  2. project aggregation
  3. assembly:assembly
  4. reporting (findbugs, checkstyle, clover, pmd, etc)
命比纸薄 2024-07-15 23:45:26

您可以使用 settings.xml 强制在本地计算机上运行的所有 Maven 构建也使用本地安装的 Maven 代理。 节省您自己和网络时间。

<settings xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profile>
        <id>localcacheproxies</id>

        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>

        <repositories>
            <repository>
                <id>localCacheProxy</id>
                <url>http://my-local-proxy.com/maven-proxy</url>
            </repository>
        </repositories>
    </profile>
</profiles>

请注意,与此处发布的其他示例相比,此 settings.xml 中的命名空间标题还提供了不错的智能感知。 (在 Windows、Linux 和 Mac 以及所有操作系统上的主目录中创建 .m2 文件夹)

You can use the settings.xml to force ALL maven builds running on your local machine to also use a locally installed maven proxy. Saving yourself and the network time.

<settings xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profile>
        <id>localcacheproxies</id>

        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>

        <repositories>
            <repository>
                <id>localCacheProxy</id>
                <url>http://my-local-proxy.com/maven-proxy</url>
            </repository>
        </repositories>
    </profile>
</profiles>

Note that the namespace headings in this settings.xml also gives a decent intellisense as opposed to other examples posted here. (create in your home directory .m2 folder on windows, linux and mac and all os'es)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文