美文网首页
maven常用插件

maven常用插件

作者: 王金松 | 来源:发表于2019-04-30 18:24 被阅读0次

[TOC]

编译java的插件

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

编译scala的插件

需要在<build>标签里面,<plugins>标签外面添加下面的配置

<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
scala插件一
<plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
scala插件二
<plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <args>
                        <arg>-target:jvm-1.8</arg>
                    </args>
                </configuration>
            </plugin>

添加依赖包的插件

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-5</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!--<archive>
                        <manifest>
                            <mainClass>com.jdcloud.stream.Main</mainClass>
                        </manifest>
                    </archive>-->
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

源码包插件和文档插件

参考:https://www.cnblogs.com/zmc/p/6375190.html

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <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>
                <configuration>
                 <reportOutputDirectory>javadocs</reportOutputDirectory>
                    <destDir>flinkx-java-docs</destDir>
                </configuration>
            </plugin>

重命名或者移动jar包

<plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <!-- here the phase you need -->
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <copy todir="${basedir}/../lib/">
                                    <fileset dir="target/">
                                        <include name="${project.name}-${project.version}.jar" />
                                    </fileset>
                                </copy>
              <copy todir="${basedir}/../plugins/">
                                    <fileset dir="target/">
                                        <include name="${project.name}-${project.version}.jar" />
                                    </fileset>
                                </copy>
                                <move file="${basedir}/../plugins/${project.name}-${project.version}.jar"
                                      tofile="${basedir}/../plugins/flinkx.jar" />
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

常见pom的编译配置

    <repositories>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </repository>

        <!--OSS-->
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>center</id>
            <name>Central Maven 2 repository</name>
            <url>http://artifactory.com/repo/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-5</version>
                <configuration>
                   <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!--<archive>
                        <manifest>
                            <mainClass>com.jdcloud.stream.Main</mainClass>
                        </manifest>
                    </archive>-->
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

相关文章

  • Maven插件

    什么是Maven的插件? Maven是一个执行插件的框架,每一个任务实际上是由插件完成的。Maven插件通常用于:...

  • maven(从零实现一个自定义插件)

    1、常用插件 查找需要的插件https://maven.apache.org/pluginshttp://www....

  • maven 常用插件

    转:https://my.oschina.net/zimingforever/blog/266191 maven打...

  • maven常用插件

    [TOC] 编译java的插件 编译scala的插件 需要在 标签里面, 标签外面添加下面的配置 scala插件一...

  • maven常用命令

    maven常用指令 打包跳过测试 idea maven控制台乱码 指定maven编译插件 清洁本地仓库 添加时间戳...

  • Maven相关知识点

    1、maven setting.xml相关知道点 2、pom.xml相关知识点 3、maven常用插件(plugi...

  • maven 插件系列1 :tomcat插件 集成

    Maven已经是Java的项目管理常用方式,本文将介绍,Maven如何使用Tomcat7插件。tomcat7-ma...

  • maven常用插件总结

    maven-compiler-plugin 用于编译项目源代码。compile目标会编译src/main/java...

  • 常用maven插件介绍

    我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编...

  • Maven常用插件整理

    一. 自带核心插件 https://maven.apache.org/plugins/ 二. 第三方插件 1.ma...

网友评论

      本文标题:maven常用插件

      本文链接:https://www.haomeiwen.com/subject/mkzvnqtx.html