为什么maven编译不能使用“pom”包装类型

发布于 2024-11-29 22:31:21 字数 3817 浏览 2 评论 0原文

我不知道为什么我的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>

I don't know why my maven build doesn't generate target/classes in current pom setting, the packaging type must be "pom" in my case, please advise what is wrong... Thanks!

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

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

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

发布评论

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

评论(3

吲‖鸣 2024-12-06 22:31:21

通过将打包类型设置为 pom,您可以指定不应编译任何内容。也许 pom 根本不是这个工件的正确打包类型?看起来您的脚本可以作为 jar 正常运行。

By setting the packaging type to pom, you specify that nothing should be compiled. Maybe pom isn't the right packaging type for this artifact after all? It looks like your script would run fine as jar.

岁月无声 2024-12-06 22:31:21

编译器插件不与打包 pom 的 Maven 生命周期中的任何阶段绑定。您必须像为程序集插件那样配置执行

<executions>
    <execution>
        <id>compile</id>
        <phase>compile</phase>
        <goals>
             <goal>compile</goal>
        </goals>
    </execution>
</executions>

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

<build>
    <sourceDirectory>${basedir}/path/to/sources</sourceDirectory>
    <!-- plugins and other configuration -->
</build>

The compiler plugin is not bound to any phase in the maven lifecycle with packaging pom. You would have to configure an execution like you did for the assemby plugin:

<executions>
    <execution>
        <id>compile</id>
        <phase>compile</phase>
        <goals>
             <goal>compile</goal>
        </goals>
    </execution>
</executions>

If your sources are in a folder other than src/main/java you would have to configure this folder in the build section of your pom:

<build>
    <sourceDirectory>${basedir}/path/to/sources</sourceDirectory>
    <!-- plugins and other configuration -->
</build>
空‖城人不在 2024-12-06 22:31:21

pom打包只是为了让其他模块继承子模块的常见和常规配置,例如插件、依赖项、贡献者、开发者……等等。请记住,它不会超出验证阶段。

这种打包是合乎逻辑的,而不是真实的,因此您不应该在该级别放置任何真实的代码或资源。如果您在 5 个子模块中使用 junit,那么您不必在 5 个 pom 文件中定义依赖项,那么您可以在带有 pom 打包的父 pom 中执行此操作,并且如果您想覆盖什么,您仍然可以在模块中指定特定版本在父 pom 中。当您运行父pom时,pom执行从父到子开始,然后从上到下检索所有依赖项。

这就是我对pom包装的理解。所以,如果你有这样的打包代码,这意味着你的 Maven 项目结构需要修改。仅使用打包pom作为多个模块之间的通用配置

pom packaging is just to let other modules inherit common and regular configurations such as plugins, dependencies, contributors, developers,....and so on for child modules. Just remember that it won't go beyond validate phase.

This packaging is logical and not real one and so you should not put any real code or resources at that level. If you use junit in say 5 child modules, so rather than defining the dependency in 5 pom files then you can just do it in the parent pom with pom packaging, and you still can specify specific version in your module if you like to override what's in the parent pom. When you run the parent pom then the pom execution starts from parent to children and then all dependencies are retrieved from up to down.

That's how i understand pom packaging. So, If you have code with such packaging this means that your maven project structure need amendment. Only use packaging pom as a common configurations between multiple modules only

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