手动写sonar plugin 一直File is not a plugin.

博客指出Sonar插件打包存在问题,本质是主pom配置导致,使用eclipse的maven install时sonar - packaging - maven - plugin未生效,添加sonar parent会使主pom报错。给出两种解决方式,一是修改jar中MANIFEST.MF文件,二是添加相关配置执行maven指令,但存在依赖包缺失问题。

原因:打包的时候有问题

标准sonar plugin 包里面的META-INF 下面的MANIFEST.MF文件如下

anifest-Version: 1.0
Plugin-Description: Enables analysis of Java Properties files.

Plugin-BuildDate: 2019-04-30T16:41:44+0800
Plugin-Display-Version: 2.7-SNAPSHOT
Archiver-Version: Plexus Archiver
SonarLint-Supported: false
Plugin-Version: 2.7-SNAPSHOT
Plugin-ChildFirstClassLoader: false
Implementation-Build: 0
Plugin-OrganizationUrl: mailto:david.racodon@gmail.com
Build-Time: 2019-04-30T08:40:46+0000
Plugin-Key: javaProperties
Plugin-Class: org.sonar.plugins.jproperties.JavaPropertiesPlugin
Created-By: Apache Maven 3.5.3
Build-Jdk: 1.8.0_131
Plugin-Name: Java Properties

而我打出来的jar 包如下:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: wanyi
Created-By: Apache Maven 3.5.3
Build-Jdk: 1.8.0_131

上面是问题的本质体现,导致原因是sonar插件是在主pom 中添加了

<parent>
    <groupId>org.sonarsource.parent</groupId>
    <artifactId>parent</artifactId>
    <version>41</version>
  </parent>

而自己开发的插件在主pom中添加:

 <plugin>
 <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
 <artifactId>sonar-packaging-maven-plugin</artifactId>
 <version>1.17</version>
 <extensions>true</extensions>
 <configuration>
	 <pluginDescription>Scanner configuration files
	 </pluginDescription>
	 <pluginKey>config-files</pluginKey>
	 <pluginName>configfiles</pluginName>
	 <pluginClass>com.lingtian.sonar.plugin.ConfigFileScanPlugin</pluginClass>
	 <sonarLintSupported>true</sonarLintSupported>
	 <sonarQubeMinVersion>5.6
	 </sonarQubeMinVersion> <!-- allow to depend on API 6.x but run on LTS -->
 </configuration>
</plugin>

使用eclipse的maven install 上面配置的sonar-packaging-maven-plugin 没有生效,但是在自写

插件中添加sonar parent,会有maven-lisence和maven-enforce 校验,主pom 报错!

解决方式:1.要么直接修改打出来的jar 中MANIFEST.MF文件

2.在主pom中添加sonar-packaging-maven-plugin, 执行maven 指令:

mvn clean package sonar-packaging:sonar-plugin,但是打出来的jar 包里面只有编译的工程代码

的class文件,并没有依赖各种的包,所以在sonar 加载运行插件的时候,报各种class not fount.

在主pom 中添加:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
   <version>3.0.1</version>
   <executions>
     <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
           <goal>copy-dependencies</goal>
        </goals>
        <configuration>
           <outputDirectory>target/lib</outputDirectory>
           <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </execution>
    </executions>
</plugin>

此时需要在主pom 中添加 <packaging>sonar-plugin</packaging> !       官方演示实例:

下载地址:https//github.com/SonarSource/sonar-custom-rules-examples

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值