2 Replies Latest reply on Mar 19, 2013 2:10 AM by kpiwko

    ShrinkWrap Maven Resolver - remove the -SNAPSHOT- trail from a dependency artifact


      Hi all.


      My problem is pretty simple, but as I am new to ShrinkWrap and Arquillian, I still cannot figure out how to solve it. I would like to try getting a response in the forum. Thanks in advance !!


      We have a J2EE application ( an EAR file ) with one particularity :


      Some dependencies are actually SNAPSHOT dependencies , but in the final EAR file, those dependency artifacts are stored without the version , or the SNAPSHOT label.

      So for example, if we have a dependency on the artifact MyArtifact-1.2-SNAPSHOT.jar , the EAR stores the artifact as MyArtifact.jar

      Additionally, the EAR has some EJB jars ( including old EJB 2.1 !! ) which are also referencing MyArtifact.jar in the Class-path of the MANIFEST.MF file


      Now, when trying to use Arquillian + ShrinkWrap to build a "micro-EAR" with only the needed dependencies, I'm of course getting some X.X-SNAPSHOT dependencies.

      However, I can't find a way to store those SNAPSHOT dependencies without the version or SNAPSHOT label, same as we do in the daily maven build.

      ( in Maven , you can use the tag <bundleFileName> to store an artifact with a different name on the EAR file )


      I'm using shrinkwrap-resolver-bom 2.0.0-alpha-5


      Is there any way to achieve this ?


      Thanks !


      So far what I have coded in my test class is this :


      public class ServiceMgmtTest {


               public static EnterpriseArchive createDeployment() {

                        Collection<String> dependencies = new ArrayList<String>();
                        File[] mavenDeps = Maven.configureResolver().fromFile("C:/DevTools/apache-maven-3.0.4/conf/settings.xml")
                       EnterpriseArchive earFile = ShrinkWrap.create(EnterpriseArchive.class)
                             .addAsManifestResource("application-test.xml", "application.xml");
                        return earFile;


               private static JavaArchive createServiceMgmtJar() {
                    JavaArchive serviceMgmtJar = ShrinkWrap.create(JavaArchive.class, "ServiceMgmt.jar");
                    serviceMgmtJar.addPackages(true, ServiceMgmtServiceFactory.class.getPackage());
                    serviceMgmtJar.addAsResource("test-persistence.xml", "META-INF/persistence.xml");
                    serviceMgmtJar.addAsResource("ejb-jar-testing.xml", "META-INF/ejb-jar.xml");
                    serviceMgmtJar.addAsResource("jboss-testing.xml", "META-INF/jboss.xml");

                    return serviceMgmtJar;


            private ServiceMgmtServiceBean serviceMgmtServiceBean;

            public void test() {


        • 1. Re: ShrinkWrap Maven Resolver - remove the -SNAPSHOT- trail from a dependency artifact

          I found a solution myself.... a bit dirty, but it works.

          If there is a better way to do it , please let me know !!


          Basically I loop over all the File items retrieved with the Maven Resolver, and if one artifact ends with "-SNAPSHOT.jar" ,

          I will add the File to the EnterpriseArchive replacing the name without the -X.X-SNAPSHOT trail, using the API .addAsModule(File , ArchivePath)

          In my case any SNAPSHOT dependency only comes from our internal company jars , and it always have the pattern  -X.X-SNAPSHOT



            EnterpriseArchive earFile = ShrinkWrap.create(EnterpriseArchive.class);

            File[] mavenDeps = Maven.configureResolver().fromFile("C:/DevTools/apache-maven-3.0.4/conf/settings.xml")

            for(int i=0;i < mavenDeps.length; i++) {


                   if(mavenDeps[i].getName().endsWith("-SNAPSHOT.jar")) {



                        String fullMavenArtifactName = mavenDeps[i].getName();
                        int indexWithoutVersion = fullMavenArtifactName.indexOf("-SNAPSHOT.jar");
                        String nameWithoutVersionOrSnapshot = fullMavenArtifactName.substring(0,indexWithoutVersion-4)+".jar";

                   } else {

          1 of 1 people found this helpful
          • 2. Re: ShrinkWrap Maven Resolver - remove the -SNAPSHOT- trail from a dependency artifact

            Hi Miguel,


            I don't think there as better solution then you've come with so far. There is a MavenImporter, which is able to package your application according to the configuration in pom.xml, but it does not support EAR packagings yet.