【问题标题】:Exclude some classes via Maven build通过 Maven 构建排除一些类
【发布时间】:2023-03-05 05:04:01
【问题描述】:

我正在将基于 Gradle 的 Android 项目转换为 Maven,并且在包含 SimpleXML Framework 时遇到了障碍。

在 Gradle 中,我可以在导入库时指定以下内容:

compile('org.simpleframework:simple-xml:2.7.+') {
        exclude module: 'stax'
        exclude module: 'stax-api'
        exclude module: 'xpp3'

请问如何在 Maven 中执行此操作?我曾尝试使用 Shade 插件,但我认为我把它弄得一团糟。这是我的尝试:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <artifactSet>
                    <excludes>
                      <exclude>stax</exclude>
                      <exclude>stax-api</exclude>
                      <exclude>xpp3</exclude>
                    </excludes>
                  </artifactSet>
                </configuration>
              </execution>
            </executions>
          </plugin>

【问题讨论】:

    标签: java android maven


    【解决方案1】:

    我认为您想要的描述如下: https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

    基本上,在要排除某些内容的库的&lt;depdency&gt; 标记中,添加&lt;exclusions&gt;。链接示例:

    <dependencies>
    <dependency>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
    

    【讨论】:

    • 完美,谢谢。我以前见过这个,但不知道组/工件 ID - 我必须进入我的 Maven 存储库并打开 SimpleXML 框架的 pom.xml 才能获得这些。希望它可以帮助别人。
    【解决方案2】:

    尝试使用 maven-compiler-plugin 它对我有用

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <excludes>
          <exclude>**/src/main/java/*.java</exclude>
        </excludes>
      </configuration>
    

    【讨论】:

    • 你能解释一下这是做什么的吗?
    猜你喜欢
    • 2021-10-31
    • 2021-03-31
    • 2014-10-06
    • 2022-06-30
    • 1970-01-01
    • 2013-01-20
    • 2012-08-20
    • 1970-01-01
    • 2012-12-06
    相关资源
    最近更新 更多