【问题标题】:Trying to add plugin in pom.xml in maven试图在 maven 的 pom.xml 中添加插件
【发布时间】:2017-06-07 10:09:54
【问题描述】:

我正在尝试在 pom.xml 中添加这个插件:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.artifactId}-${project.version}-withDependency-ShadedForAndroid</finalName>
                            <artifactSet>
                                <includes>
                                    <include>com.mashape.unirest:unirest-java</include>
                                    <include>org.apache.httpcomponents:httpclient</include>
                                    <include>org.apache.httpcomponents:httpcore</include>
                                    <include>org.apache.httpcomponents:httpcore-nio</include>
                                    <include>org.apache.httpcomponents:httpasyncclient</include>
                                    <include>org.apache.httpcomponents:httpmime</include>
                                    <include>org.json:json</include>
                                    <include>commons-logging:commons-logging</include>
                                    <include>commons-codec:commons-codec</include>
                                </includes>
                            </artifactSet>
                            <relocations>
                                <relocation>
                                    <pattern>org.apache.http</pattern>
                                    <shadedPattern>com.mashape.relocation</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

在这个 pom.xml 中:

<?xml version="1.0"?>
<project 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/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mashape.unirest</groupId>
    <artifactId>unirest-java</artifactId>
    <packaging>jar</packaging>
    <version>1.4.10-SNAPSHOT</version>
    <name>unirest-java</name>
    <description>Simplified, lightweight HTTP client library</description>
    <url>http://unirest.io/</url>

    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>7</version>
    </parent>

    <licenses>
        <license>
            <name>MIT</name>
            <url>http://opensource.org/licenses/MIT</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url>https://github.com/Mashape/unirest-java</url>
        <connection>scm:git:git@github.com:Mashape/unirest-java.git</connection>
        <developerConnection>scm:git:git@github.com:Mashape/unirest-java.git</developerConnection>
    </scm>

    <developers>
        <developer>
            <id>mashape</id>
            <name>Mashape</name>
            <email>opensource@mashape.com</email>
            <url>https://github.com/Mashape</url>
            <organization>Mashape</organization>
            <organizationUrl>https://www.mashape.com</organizationUrl>
        </developer>
    </developers>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <jackson.version>2.6.0</jackson.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <fork>true</fork>
                    <meminitial>128m</meminitial>
                    <maxmem>512m</maxmem>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160212</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

但是如果有人可以解释我,我不知道该怎么做;当我尝试时,我有一些关于把它放在错误的地方的问题。无法识别的标签'插件'.. 谢谢。

【问题讨论】:

    标签: java xml maven pom.xml


    【解决方案1】:

    您的 POM 中有已经定义的插件标签。您可以在其中添加另一个插件。看一个例子;

    <build>
     <plugins>
      <plugin>
      <!-- first plugin here -->
      </plugin>
      <plugin>
      <!-- second plugin here -->
      </plugin>
     </plugins>
    </build>
    

    在 POM 中包含提供的插件后,我已经完成了你的 POM

    <?xml version="1.0"?>
    <project 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/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mashape.unirest</groupId>
    <artifactId>unirest-java</artifactId>
    <packaging>jar</packaging>
    <version>1.4.10-SNAPSHOT</version>
    <name>unirest-java</name>
    <description>Simplified, lightweight HTTP client library</description>
    <url>http://unirest.io/</url>
    
    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>7</version>
    </parent>
    
    <licenses>
        <license>
            <name>MIT</name>
            <url>http://opensource.org/licenses/MIT</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    
    <scm>
        <url>https://github.com/Mashape/unirest-java</url>
        <connection>scm:git:git@github.com:Mashape/unirest-java.git</connection>
        <developerConnection>scm:git:git@github.com:Mashape/unirest-java.git</developerConnection>
    </scm>
    
    <developers>
        <developer>
            <id>mashape</id>
            <name>Mashape</name>
            <email>opensource@mashape.com</email>
            <url>https://github.com/Mashape</url>
            <organization>Mashape</organization>
            <organizationUrl>https://www.mashape.com</organizationUrl>
        </developer>
    </developers>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <jackson.version>2.6.0</jackson.version>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <fork>true</fork>
                    <meminitial>128m</meminitial>
                    <maxmem>512m</maxmem>
                    <source>1.5</source>
                    <target>1.5</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.artifactId}-${project.version}-withDependency-ShadedForAndroid</finalName>
                            <artifactSet>
                                <includes>
                                    <include>com.mashape.unirest:unirest-java</include>
                                    <include>org.apache.httpcomponents:httpclient</include>
                                    <include>org.apache.httpcomponents:httpcore</include>
                                    <include>org.apache.httpcomponents:httpcore-nio</include>
                                    <include>org.apache.httpcomponents:httpasyncclient</include>
                                    <include>org.apache.httpcomponents:httpmime</include>
                                    <include>org.json:json</include>
                                    <include>commons-logging:commons-logging</include>
                                    <include>commons-codec:commons-codec</include>
                                </includes>
                            </artifactSet>
                            <relocations>
                                <relocation>
                                    <pattern>org.apache.http</pattern>
                                    <shadedPattern>com.mashape.relocation</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160212</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    </project>
    

    【讨论】:

    • 谢谢,这行得通,但我还有另一个问题,当我启动 mvn clean assembly:assembly 时它告诉我:未能执行目标.org.apache.maven.plugins:maven-compiler- plugin:3.1:compile 请问我该怎么办?
    • 请发布完整的错误信息?线索将在消息中!
    • 这就是我所拥有的,当我删除这个时,我对另一个有同样的看法,我不明白。我正在尝试做这些事情:blog.mashape.com/using-unirest-java-for-your-android-projects 我从一开始就开始了,但是 mvn clean assembly:assembly 不想工作
    【解决方案2】:

    应该在插件里面

      <build>
            <plugins>
    
                  <YOUR PLUGIN>
    
             </plugins>
        </build>
    

    【讨论】:

      【解决方案3】:

      这是一个示例,它显示了放置插件和依赖项的位置。

      <project 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/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>MavenTest</groupId>
      <artifactId>MavenTest</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      
      <dependencies>
          <dependency>
              <groupId>org.seleniumhq.selenium</groupId>
              <artifactId>selenium-java</artifactId>
              <version>2.45.0</version>
          </dependency>
          <dependency>
              <groupId>org.testng</groupId>
              <artifactId>testng</artifactId>
              <version>6.8</version>
              <scope>test</scope>
          </dependency>
          <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>3.8.1</version>
              <scope>test</scope>
          </dependency>
      </dependencies>
      
      <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>2.3.2</version>
                  <configuration>
                      <source>1.7</source>
                      <target>1.7</target>
                  </configuration>
              </plugin>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-surefire-plugins</artifactId>
                  <version>2.12</version>
                  <inherited>true</inherited>
                  <configuration>
                      <suiteXmlFiles>
                          <suuiteXmlFile>testng.xml</suuiteXmlFile>
                      </suiteXmlFiles>
                  </configuration>
              </plugin>
          </plugins>
      </build>
      

      【讨论】:

        猜你喜欢
        • 2022-01-17
        • 2014-07-27
        • 1970-01-01
        • 1970-01-01
        • 2012-07-04
        • 1970-01-01
        • 1970-01-01
        • 2020-03-20
        • 1970-01-01
        相关资源
        最近更新 更多