jim
jim

Reputation: 9138

Exclude some classes via Maven build

I am converting a Gradle based Android project to Maven and have hit a speed bump when it comes to including the SimpleXML Framework.

In Gradle I can specify the following when importing the library:

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

How can I do this in Maven please? I have tried using the Shade plugin but I think I made a mess of that. Here is my attempt:

<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>

Upvotes: 1

Views: 245

Answers (2)

Marcus Widegren
Marcus Widegren

Reputation: 540

I think what you want is described here: https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

Basically, within the <depdency> tag of the library where you want to exclude something, you add <exclusions>. Example from the link:

<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>

Upvotes: 2

kirti
kirti

Reputation: 4609

Try using maven-compiler-plugin it works for me

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

Upvotes: 0

Related Questions