iwarapter / gradle-sonar-packaging-plugin

Gradle Plugin for building SonarQube plugins.
Other
19 stars 11 forks source link

`pluginPackaging` failed in gradle multiproject #16

Closed goprayogo closed 7 years ago

goprayogo commented 7 years ago

I set-up a gradle multi project for sonar plugin, and every time i do ./gradlew clean build, the build failed on pluginPackaging task.

I need to have the sonar plugin as part of a gradle multiproject set up, and i have the following gradle.build

buildscript {
    ext {
        versions = [
                gradleSonar         : "0.1.4"
        ]
        sonar_example_plugin = "0.0.1"
    }

    dependencies {
        classpath "gradle.plugin.com.iadams.plugins:gradle-sonar-packaging-plugin:${versions.gradleSonar}"
    }
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        mavenCentral()
        jcenter()
    }
}

allprojects {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        mavenCentral()
        jcenter()
    }
}

subprojects {
    apply plugin: 'java'
}

project (":sonar-example-plugin"){
    apply plugin: 'com.iadams.sonar-packaging'

    dependencies {
        provided 'org.sonarsource.sonarqube:sonar-plugin-api:5.6'
    }

    pluginPackaging.dependsOn "compileJava"

    sonarPackaging {
        serverUrl = 'http://localhost:9000'
        pluginDir = '/tmp/sonarqube-5.1/extensions/plugins'
        pluginKey = 'example'
        pluginClass = 'org.sonarsource.plugins.example.ExamplePlugin'
        pluginName = 'Example'
        pluginDescription = 'Exmaple'
        pluginParent = null
        pluginLicense = 'MIT'
        requirePlugins = null
        pluginDevelopers = 'Gama Ogi Prayogo'
        skipDependenciesPackaging = false
        useChildFirstClassLoader = false
    }

}

The error that I've got when executing build

* What went wrong:
Execution failed for task ':sonar-example-plugin:pluginPackaging'.
> Plugin class not found: org.sonarsource.plugins.example.ExamplePlugin

If I execute gradle build in the child directory with the build.gradle as suggested in README.md, all is good.

iwarapter commented 7 years ago

In my plugin i setup the dependency on the plugin in the actual module using it - see https://github.com/iwarapter/sonar-puppet/blob/master/sonar-puppet-plugin/build.gradle

I'm assuming your setup is like this:

root
| - module A
| - module B 
| - sonar-example-plugin 

In which case i would of thought the section in the root build.gradle :

project (":sonar-example-plugin"){
    apply plugin: 'com.iadams.sonar-packaging'

Would of worked as expected, i'll setup some tests for this when I get back from work.

iwarapter commented 7 years ago

This works fine for me can you just confirm you have a class here: cat sonar-example-plugin/src/main/java/org/sonarsource/plugins/example/ExamplePlugin.java

package org.sonarsource.plugins.example;

import java.util.Arrays;
import java.util.List;

import org.sonar.api.SonarPlugin;

public class ExamplePlugin extends SonarPlugin {

  @Override
  public List getExtensions() {
    return Arrays.asList();
  }
}
goprayogo commented 7 years ago

Hi, I think this issue can be closed.

The issue is solved by adding the following statement in the build.gradle of the sub-module.

pluginPackaging.dependsOn 'compileJava'

Full sample project can be viewed here

otrosien commented 7 years ago

well, if there's such a dependency the plugin should register it by itself...

iwarapter commented 7 years ago

@otrosien @goprayogo you don't need to add that as its done automatically.

There is an example project here: https://github.com/iwarapter/gradle-sonar-packaging-plugin-issue-16