4

I need to create a real IT test using Arquillian for my EAR application.

Since ShrinkWrap methods addClasses or addPackages are useless in real world - because of too many imports needed - I'd like to use Maven.resolver() which works with pom.xml.

Therefore I've created a Test like this:

@RunWith(Arquillian.class)
public class ArqTest {

@Deployment
public static Archive<?> createTestArchive() {
    System.out.println("START CREATE ARCHIVE");

    //create ear archive  
    EnterpriseArchive ear = ShrinkWrap
            .create(EnterpriseArchive.class);  

    System.out.println("RESOLVING EJB DEPENDENCIES");

    // resolve and add ejbDependencies to ear lib  
    File[] ejbDependencies = Maven.resolver()
            .loadPomFromFile("../ejb/pom.xml")
            .importRuntimeDependencies()
            .resolve()
            .withTransitivity()
            .asFile();   

    System.out.println("ADDING DEPENDENCIES TO EAR");

    for (File archive : ejbDependencies) {  
        ear.addAsLibrary(archive);  
    }   

    System.out.println("START CREATE EJB");
    // resolve ejb (actually jar file cause as of now mavenimporter doesn't support ejb-types ony war and jars so don't be fooled by my naming convention)  
    // then add some external resources, and an empty beans.xml for CDI to work  
    JavaArchive ejb = ShrinkWrap                
            .create(MavenImporter.class)                
            .loadPomFromFile("../ejb/pom.xml")
            .importBuildOutput()                
            .as(JavaArchive.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsResource("app.properties")
            ;

    System.out.println("START CREATE WAR");
    //resolve war and add beans.xml and my html files manually  
    WebArchive war = ShrinkWrap
            .create(MavenImporter.class)
            .loadPomFromFile("pom.xml")
            .importBuildOutput()
            .as(WebArchive.class)               
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            ;

    //add built modules to ear and my application.xml  
    ear.addAsModule(ejb);  
    ear.addAsModule(war);
    ear.setApplicationXML("application.xml");

    System.out.println("END CREATE ARCHIVE");

    return ear;
}

However, it fails creating archive while "RESOLVING EJB DEPENDENCIES" and throw this error

Caused by: java.lang.IllegalArgumentException: No dependencies were set for resolution
at org.jboss.shrinkwrap.resolver.impl.maven.util.Validate.notEmpty(Validate.java:78)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenStrategyStageBaseImpl.using(MavenStrategyStageBaseImpl.java:65)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenStrategyStageBaseImpl.withTransitivity(MavenStrategyStageBaseImpl.java:49)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenStrategyStageBaseImpl.withTransitivity(MavenStrategyStageBaseImpl.java:38)
at ArqEjbTest.createTestArchive(ArqEjbTest.java:39)
... 61 more

Anyone had success with creating an archive ?

Fabrizio Stellato
  • 1,727
  • 21
  • 52
  • Tried also with WAR instead of EAR, had same results! "java.lang.IllegalArgumentException: No dependencies were set for resolution" – oikonomopo Feb 15 '17 at 15:51
  • write your answer in Answer section, not inside question to get the bounty. It's also the right way to be Q&A clear. – oikonomopo Feb 17 '17 at 11:03

1 Answers1

2

I finally solved with the following code:

System.out.println("RESOLVING EJB DEPENDENCIES");

// resolve and add ejbDependencies to ear lib  
File[] ejbDependencies = Maven.resolver()
    .loadPomFromFile("../project-ejb/pom.xml")
    .importRuntimeDependencies()
    .resolve()
    .withTransitivity()
    .asFile();   

for (File archive : ejbDependencies) {  
    ear.addAsLibrary(archive);  
}   

System.out.println("START CREATE EJB");
// resolve ejb (actually jar file cause as of now mavenimporter doesn't support ejb-types ony war and jars so don't be fooled by my naming convention)  
// then add some external resources, and an empty beans.xml for CDI to work  
JavaArchive ejb = ShrinkWrap
    .create(JavaArchive.class, "project-test-ejb.jar")              
    .addPackage("it.blah..")                
    .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
    ;

The rest remains the same.

Adding this line to arquillian.xml

<engine>
    <property name="deploymentExportPath">target/deployment</property>
</engine>

also help a lot because with the above property arquillian creates the result package that can be analyzed to get rid of errors.

Fabrizio Stellato
  • 1,727
  • 21
  • 52
  • Is your maven repo behind proxy? I have the same IllegalArgumentException(No dependencies were set for resolution) at Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve()... Had you encountered anything similar? – oikonomopo Feb 17 '17 at 13:20
  • No I'm not behind proxy – Fabrizio Stellato Feb 20 '17 at 09:31