为什么maven编译不适用于"pom"打包类型

Eve*_*ven 5 maven-2 target maven-assembly-plugin maven-compiler-plugin

我不知道为什么我的maven构建在当前pom设置中不会生成目标/类,在我的情况下包装类型必须是"pom",请告知错误...谢谢!

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.sm.doctor</groupId>
<artifactId>smdoctor</artifactId>
<packaging>pom</packaging>
<version>${SMDOCTOR_VERSION}</version>
<name>sm doctor</name>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    <plugins>   
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
                <debug>true</debug>
                <debuglevel>source,lines</debuglevel>
                <showDeprecation>true</showDeprecation>
                <archive>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>         
                <finalName>smdoctor</finalName> 
                <descriptors>
                    <descriptor>dist.xml</descriptor>
                    <descriptor>zip.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
      <execution>
        <id>attach-artifacts</id>
        <phase>package</phase>
        <goals>
          <goal>attach-artifact</goal>
        </goals>
        <configuration>
          <artifacts>
            <artifact>
              <file>target/smdoctor.zip</file>
              <type>zip</type>
            </artifact>
          </artifacts>
        </configuration>
      </execution>
    </executions>
  </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>...</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <version>2.3.1</version>
        </plugin>
    </plugins>
</build>
<dependencies>
    ... 
     </dependencies>
Run Code Online (Sandbox Code Playgroud)

dds*_*dso 7

通过将包装类型设置为pom,您可以指定不应编译任何内容.pom毕竟这个工件可能不是正确的包装类型?看起来你的脚本运行正常jar.

  • 这听起来你在Maven中做错了,因为如果你需要打包pom,这意味着通常你在root中有多模块构建但是root不应该生成jar.如果你需要创建一个jar而不是使用包装类型jar ... (5认同)

Jör*_*ann 5

编译器插件没有绑定到包装pom的maven生命周期中的任何阶段.你必须配置execution你为assemby插件做的事情:

<executions>
    <execution>
        <id>compile</id>
        <phase>compile</phase>
        <goals>
             <goal>compile</goal>
        </goals>
    </execution>
</executions>
Run Code Online (Sandbox Code Playgroud)

如果您的源位于src/main/java以外的文件夹中,则必须在pom的build部分中配置此文件夹:

<build>
    <sourceDirectory>${basedir}/path/to/sources</sourceDirectory>
    <!-- plugins and other configuration -->
</build>
Run Code Online (Sandbox Code Playgroud)