maven问题汇总

1.修复 Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:build-helper-maven-plugin:1.8:add-source (execution: add-source, phase: generate-sources)


在maven项目中使用add-source时,pom.xml报如下错误:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:build-helper-maven-plugin:1.8:add-source (execution: add-source, phase: generate-sources)

加入的代码如下:

 <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>build-helper-maven-plugin</artifactId>
           <version>3.0</version>
           <executions>
              <execution>
                 <id>add-source</id>
                 <phase>generate-sources</phase>
                 <goals>
                      <goal>add-source</goal>
                  </goals>
                   <configuration>
                        <sources>
                             <source>${project.basedir}/src/main/java</source>
                             <source>${project.basedir}/src/main/web</source>
                             <source>${project.basedir}/src/main/form</source>
                             <source>${project.basedir}/src/main/flow</source>
                             <source>${project.basedir}/src/main/report</source>
                        </sources>
                    </configuration>
                 </execution>
             </executions>
         </plugin>

原因是eclipse的m2e插件还没支持到execution,解决办法如下
在pom.xml文件中,<plugins></plugins>后加入如下代码:

<pluginManagement>
    <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>
                                    org.codehaus.mojo
                                </groupId>
                                <artifactId>
                                    build-helper-maven-plugin
                                </artifactId>
                                <versionRange>
                                    [1.8,)
                                </versionRange>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <ignore></ignore>
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

然后maven -> Update Project 即可


**续:仅仅加tag:<pluginManagement></pluginManagement>解决了问题。**


2.插件没找到
在 IntelliJ IDEA 中,pom.xml 里的插件找不到并报红,如下图:
这里写图片描述
Plugin ‘’‘org.apache.maven.plugins:maven-gpg-plugin:1.6’’’ not found
Inspects a Maven model for resolution problems.

两种解决方法:
方案一:手动下载

mvn dependency:get -DrepoUrl=http://repo.maven.apache.org/maven2/ -Dartifact=org.apache.maven.plugins:maven-gpg-plugin:1.6

方案二:在 IntelliJ IDEA 中更新 Indexed Maven Repositories

步骤: IntelliJ IDEA -> Preferences -> Build,Execution,Deployment -> Build Tools -> Mavne -> Repositories -> Remote URL -> Update

版本发布

参考:
创建发布包,github

https://github.com/waylau/github-help/blob/master/Creating Releases 创建发布包.md

注意:pom.xml 的 distributionManagement 中 snapshotRepository 与 repository 中的 id 与 setting.xml 中 server 的 id 要一致

setting.xml中,server:

<server>  
  <id>nexus-releases</id>  
  <username>admin</username>  
  <password>admin123</password>  
</server>  
  
<server>  
  <id>nexus-snapshots</id>  
  <username>admin</username>  
  <password>admin123</password>  
</server>  
pom.xml文件中distributionManagement:

   <!--定义snapshots库和releases库的nexus地址-->  
    <distributionManagement>  
        <repository>  
            <id>nexus-releases</id>  
            <url>  
                http://172.17.103.59:8081/nexus/content/repositories/releases/  
            </url>  
        </repository>  
        <snapshotRepository>  
            <id>nexus-snapshots</id>  
            <url>  
                http://172.17.103.59:8081/nexus/content/repositories/snapshots/  
            </url>  
        </snapshotRepository>  
    </distributionManagement>  

在项目的 pom.xml 中配置 release 的插件

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>${plugin.release.version}</version>
    <configuration>
        <tagNameFormat>v@{project.version}</tagNameFormat>//tag格式
        <autoVersionSubmodules>true</autoVersionSubmodules>
    </configuration>
</plugin>


或者:
<configuration>  
          <providerImplementations>  
            <git>jgit</git>  
          </providerImplementations>  
          <username>xxxusername</username>  
          <password>xxxxpasswrod</password>  
          <tagBase>${project.artifactId}-${project.version}</tagBase> //tag格式 
          <goals>-f pom.xml deploy</goals>  
        </configuration>  
pom.xml中配置Scm:

<scm>  
      #git项目地址可以用SSH  也可以用 HTTPS的      
      <connection>scm:git:http://10.69.205.31:8886/mazhenbang/maven_scm.git</connection>    #git项目地址可以用SSH  也可以用 HTTPS的  
      <developerConnection>scm:git:http://10.69.205.31:8886/mazhenbang/maven_scm.git</developerConnection>  
     #git项目浏览器里的地址     
     <url>http://10.69.205.31:8886/mazhenbang/maven_scm/tree/master</url>  
</scm>  
使用下面的指令即可直接在 github 远程仓库生成发行版本
mvn clean
mvn release:prepare
执行完这条命令,你去git仓库看一下pom里的version,已经神奇的变成0.0.3-SNAPSHOT。并且在会给你生成一个tag。
mvn release:perform
这条命令主要做的是:
a.去git的tag上拿代码
b.用tag上的代码,打一个release版的包
c.deploy上你的maven私服

编码GBK的不可映射字符

由于代码使用的UTF-8,而maven编译的时候使用的GBK的缘故

解决方法一:
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

解决二:
在pom.xml中加入maven plugin
<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>utf8</encoding> 
    </configuration>
</plugin>

springboot : mvn package jar无法启动

背景:springboot项目A,依赖项目B,执行mvn package 打出jar 无法启动。
原因:B项目相同的包下面有main()函数!!!!!!

这个问题mvn package报错信息:com.xxx.xxx包找不到,实际上com.xxx.xxx是存在的。依赖也能加载。
把B项目的main()干掉一切正常!!!!

还有一种解决方式:
spring-boot-maven-plugin指定main

<properties>
    <!-- The main class to start by executing java -jar -->
    <start-class>com.microservice.MicroserviceOrderApplication</start-class>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.yihaomen.SpringBootWebApplication</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

maven archetype实践

1.创建archetype项目my-maven-archetype
2.new project->create maven project->create from archetype->add archetype
3.等待创建

删除archetype

删除自己创建的 Maven 骨架(Archetypes)
windows:

C:\Users\${user}.IntelliJIdea${version}\system\Maven\Indices-> UserArchetypes.xml 
删除不需要的archetype配置,重启
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值