简体   繁体   English

Arquillan InvalidEnvironnmentException,建议将已添加的插件添加到Maven pom.xml

[英]Arquillan InvalidEnvironnmentException, suggests to add an already added plugin to Maven pom.xml

I configured my project and wrote my test class for a multi-module project. 我配置了项目,并为一个多模块项目编写了测试类。 A test for a business service call to an AS400 server is written with Arquillan, which gives me an InvalidEnvironnmentException when I run the test. 用Arquillan编写了对对AS400服务器的业务服务调用的测试,该测试在运行测试时给我一个InvalidEnvironnmentException

package com.my.company.theproject.business.service.protect;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.my.company.theproject.common.dataaccess.PojoService;
import com.my.company.theproject.ServiceContext;

@RunWith(Arquillian.class)
public class SampleServiceTest
{

    @Inject
    @PojoService
    SampleService service;

    private ServiceContext context;

    @Before
    public void setUp()
        throws Exception
    {

        context = new ServiceContext();
    }

    @Deployment
    public static WebArchive createDeployment()
    {
        return ShrinkWrap
            .create(WebArchive.class)
            .addClasses(SampleService.class)
            .addAsWebInfResource("META-INF/beans.xml", ArchivePaths.create("beans.xml"))
            .addAsLibraries(
                Maven.configureResolverViaPlugin().importRuntimeDependencies().resolve().withTransitivity().asFile());
    }

    @Test
    public void test()
    {

        List<String> list = new ArrayList<String>();
        list.add("AAA");

        service.getStoredProcedureParameters(context, list);

        fail("To be implemented");
    }
}

I have written down the imports here, in case some were wrong (eg javax.inject.Inject ?). 我在这里写下了导入,以防某些错误(例如javax.inject.Inject?)。

The problem here is that Arquillian gives me this error at test runtime (first exception of the stack trace) : 这里的问题是Arquillian在测试运行时给了我这个错误(堆栈跟踪的第一个异常):

java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive com.sopra.banking.packbanque.business.service.protect.SampleServiceTest.createDeployment() java.lang.RuntimeException:无法调用部署方法:public static org.jboss.shrinkwrap.api.spec.WebArchive com.sopra.banking.packbanque.business.service.protect.SampleServiceTest.createDeployment()

At the end of the stack trace, I see this : 在堆栈跟踪的末尾,我看到了:

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:177)
    ... 50 more
Caused by: org.jboss.shrinkwrap.resolver.api.maven.InvalidEnvironmentException: Configuration from environment requires that user has following properties set, however they were not detected in runtime environment:
    maven.execution.pom-file
    maven.execution.offline
    maven.execution.user-settings
    maven.execution.global-settings
    maven.execution.active-profiles

You should enable ShrinkWrap Maven Resolver Plugin to get them set for you automatically if executing from Maven via adding following to your <build> section:

<plugin>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>propagate-execution-context</goal>
            </goals>
        </execution>
    </executions>
</plugin>

    at org.jboss.shrinkwrap.resolver.impl.maven.task.ConfigureSettingsFromPluginTask.execute(ConfigureSettingsFromPluginTask.java:71)
    at org.jboss.shrinkwrap.resolver.impl.maven.ConfigurableMavenResolverSystemBaseImpl.configureViaPlugin(ConfigurableMavenResolverSystemBaseImpl.java:119)
    at org.jboss.shrinkwrap.resolver.api.maven.Maven.configureResolverViaPlugin(Maven.java:77)
    at org.jboss.shrinkwrap.resolver.api.maven.Maven.configureResolverViaPlugin(Maven.java:59)
    at com.sopra.banking.packbanque.business.service.protect.SampleServiceTest.createDeployment(SampleServiceTest.java:74)
    ... 55 more

The problem is that this plugin declaration is already in my Maven pom.xml ! 问题在于此插件声明已经在我的Maven pom.xml中!

<build>
    <plugins>
        <plugin>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-maven-plugin</artifactId>
            <version>2.2.0-beta-2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>propagate-execution-context</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

What is the problem here ? 这里有什么问题 ?

I think the problem could be that you need to load the pom file first and then resolve as of now it dosent know that whene to resolve the dependencies from.. 我认为问题可能是您需要先加载pom文件,然后从现在开始进行解析,否则它就知道何时从中解析依赖项。

I am not sure but you can try this... :) 我不确定,但是您可以尝试一下... :)

You can find everything about shrikwrap resolver here : 您可以在此处找到有关shrikwrap解析器的所有信息:

https://github.com/shrinkwrap/resolver https://github.com/shrinkwrap/resolver

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM