Search code examples
mavenintegration-testingjboss-arquillianshrinkwrap

ShrinkWrap Maven resolver can't find war artifact in local repo


I've an integration test where I'm deploying 2 web services in Wildfly using Arquillian and ShrinkWrap resolver. Both services are independent such that neither is dependent on the other in any Maven dependency sense. Service 2 makes a HTTP call to service 1. This is purely a B2B scenario where one component calls out to another. That said, here's my test. Problem is, Arquillian fails to deploy the service 1. Since ShrinkWrap error messages are just useless (there're actually no messages), I'm trying to figure out what am I doing wrong. I've verified that the artifact for service 1 does exist in my local Maven repo.

@Deployment(name = AVAILABILITY_SERVICE_NAME, order = 1)
public static WebArchive createAvailabilityServiceDeployment() {
    WebArchive availabilityService = Maven.configureResolver()
        .workOffline().withMavenCentralRepo(false)
        .withClassPathResolution(true)
        .resolve(AVAILABILITY_SERVICE_MVN_COORD).withoutTransitivity()
        .asSingle(WebArchive.class);

    System.out.println(availabilityService.toString(true));

    return availabilityService;
}

@Deployment(name = APPOINTMENT_SERVICE_NAME, order = 2)
public static WebArchive createAppointmentServiceDeployment()
        throws FileNotFoundException {
    WebArchive appointmentService = create(WebArchive.class,
        APPOINTMENT_SERVICE_NAME + ".war").addPackages(true,
        Filters.exclude(".*Test.*"), AppointmentApp.class.getPackage())
        .addAsWebInfResource(EmptyAsset.INSTANCE,
            ArchivePaths.create("beans.xml"));

    System.out.println(appointmentService.toString(true));

    return appointmentService;
}

java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive name.abhijitsarkar.microservices.appointment.AppointmentResourceIT.createAvailabilityServiceDeployment()
    at org.jboss.shrinkwrap.resolver.spi.format.FormatProcessors.find(FormatProcessors.java:53)
    at org.jboss.shrinkwrap.resolver.impl.maven.MavenFormatStageImpl.as(MavenFormatStageImpl.java:82)
    at org.jboss.shrinkwrap.resolver.impl.maven.MavenFormatStageImpl.asSingle(MavenFormatStageImpl.java:100)
    at name.abhijitsarkar.microservices.appointment.AppointmentResourceIT.createAvailabilityServiceDeployment(AppointmentResourceIT.java:50)

Solution

  • Apparently, it needs to be done in 2 steps. Hope it helps someone else.

    private static WebArchive createDependentServiceDeployment(String name) {
        String mvnCoordinate = join(":", DEPENDENT_SERVICE_GROUP, name,
            DEPENDENT_SERVICE_PACKAGING, DEPENDENT_SERVICE_VERSION);
        File service = Maven.configureResolver().workOffline()
            .withMavenCentralRepo(false).withClassPathResolution(true)
            .resolve(mvnCoordinate).withoutTransitivity().asSingleFile();
    
        return ShrinkWrap.create(ZipImporter.class,
            join(".", name, DEPENDENT_SERVICE_PACKAGING))
           .importFrom(service).as(WebArchive.class);
    }