使用IntegrationSpec类时,nebula-test无法加载项目插件类

时间:2016-01-13 15:50:06

标签: groovy gradle spock nebula-test

我正在编写和测试Gradle插件。当我尝试测试插件时,我得到一个错误,表明无法找到插件类?如果我使用插件ID,我会得到:插件ID为<>未找到。如果我使用插件类名,我得到:在根项目中找不到属性'com'。

下面是build.gradle,ExamplePlugin类和Test Spec。

的build.gradle

apply plugin: 'idea'
apply plugin: 'groovy'
apply plugin: 'maven'

group = 'com.sas'
version = '0.1.0'

description = "Project to test with nebula plugin."

task wrapper(type: Wrapper) {
    gradleVersion = '2.6' //version required
}

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile localGroovy()
    compile gradleApi()

    testCompile 'org.spockframework:spock-core:1.0-groovy-2.3'
    testCompile 'com.netflix.nebula:nebula-test:3.1.0'
}

插件类

package com.sas.gradle.plugins.example

import org.gradle.api.Plugin
import org.gradle.api.Project

class ExamplePlugin implements Plugin<Project> {
    @Override
    void apply(Project project) {
        project.logger.debug("ExamplePlugin: Running...")
    }
}

测试类规范

package com.sas.gradle.plugins.example

import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult

class ExamplePluginIntegSpec extends IntegrationSpec {

    def 'setup and display the buildscript classpath'() {
        writeHelloWorld('example.hello')
        buildFile << '''
            apply plugin: 'java'
            apply plugin: com.sas.gradle.plugins.example.ExamplePlugin
            task show << {
                buildscript.configurations.classpath.each { println it }
            }
        '''.stripIndent()

        when:
        ExecutionResult result = runTasksSuccessfully('show')

        then:
        result.standardOutput.contains(':show')
    }
}

在使用IntegrationSpec时,它会在build / test / / 规范中创建构建脚本build.gradle和settings.gradle 位置。另外,我在同一位置看到.gradle,.gradle-test-kit,src目录。我想知道如何设置.classpath来运行测试,并注意到.gradle-test-kit中的init.gradle脚本;然后在其中我找到了allprojects-&gt; buildscript-&gt;依赖关系&gt; classpath DSL。 然后我注意到我的插件类(编译为build / classes / main)不在列表中?我想过星云测试IntegrationSpec类会做到这一点吗?通过添加此DSL:

buildscript {
    dependencies {
        classpath files('../../../../build/classes/main')
    }
}

提前感谢您的帮助, 吉姆

最后这是我得到的例外:

Class com.sas.gradle.plugins.example.ExamplePluginIntegSpec
all > com.sas.gradle.plugins.example > ExamplePluginIntegSpec
1
tests
1
failures
0
ignored
3.173s
duration
0%
successful
Failed tests
Tests
Standard output
Standard error
setup and display the buildscript classpath

org.gradle.api.GradleException: Build aborted because of an internal error.
    at nebula.test.functional.internal.DefaultExecutionResult.rethrowFailure(DefaultExecutionResult.groovy:97)
    at nebula.test.IntegrationSpec.runTasksSuccessfully(IntegrationSpec.groovy:265)
    at com.sas.gradle.plugins.example.ExamplePluginIntegSpec.setup and display the buildscript classpath(ExamplePluginIntegSpec.groovy:19)
Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'C:\Users\japoli\IdeaProjects\nebula-test-example-master\build\test\com.sas.gradle.plugins.example.ExamplePluginIntegSpec\setup-and-display-the-buildscript-classpath\build.gradle' line: 4
A problem occurred evaluating root project 'setup-and-display-the-buildscript-classpath'.
    at org.gradle.initialization.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:74)
    at org.gradle.initialization.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
    at org.gradle.initialization.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:105)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:97)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:97)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:102)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:46)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:58)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:77)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:47)
    at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:52)
    at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:35)
    at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:63)
    at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:35)
    at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:124)
    at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:100)
    at org.gradle.tooling.internal.provider.DefaultConnection.getModel(DefaultConnection.java:167)
    at org.gradle.tooling.internal.consumer.connection.CancellableModelBuilderBackedModelProducer.produceModel(CancellableModelBuilderBackedModelProducer.java:58)
    at org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection.run(AbstractConsumerConnection.java:58)
    at org.gradle.tooling.internal.consumer.DefaultBuildLauncher$1.run(DefaultBuildLauncher.java:84)
    at org.gradle.tooling.internal.consumer.DefaultBuildLauncher$1.run(DefaultBuildLauncher.java:78)
    at org.gradle.tooling.internal.consumer.connection.LazyConsumerActionExecutor.run(LazyConsumerActionExecutor.java:83)
    at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConsumerActionExecutor.run(ProgressLoggingConsumerActionExecutor.java:58)
    at org.gradle.tooling.internal.consumer.connection.RethrowingErrorsConsumerActionExecutor.run(RethrowingErrorsConsumerActionExecutor.java:38)
    at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:55)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'setup-and-display-the-buildscript-classpath'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$1.run(DefaultScriptPluginFactory.java:148)
    at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:72)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:153)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:495)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:89)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLauncher.java:129)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:126)
    at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:36)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:103)
    ... 31 more
Caused by: groovy.lang.MissingPropertyException: Could not find property 'com' on root project 'setup-and-display-the-buildscript-classpath'.
    at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(AbstractDynamicObject.java:43)
    at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:35)
    at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:97)
    at org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.java:66)
    at build_3ap3e1c6wmmpxvu497fssx7g9.run(C:\Users\japoli\IdeaProjects\nebula-test-example-master\build\test\com.sas.gradle.plugins.example.ExamplePluginIntegSpec\setup-and-display-the-buildscript-classpath\build.gradle:4)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
    ... 49 more
Wrap lines 
Generated by Gradle 2.6 at Jan 13, 2016 10:01:59 AM

1 个答案:

答案 0 :(得分:0)

您是否看过Gradle TestKit(星云测试的功能替代品)?看一下specific section关于将测试代码放在类路径上的信息。