4 Replies Latest reply on Jun 27, 2013 3:52 AM by bmajsak

    Include package in src/main/java but exclude package in src/test/java

    squidy

      Hello

       

      I have a normal maven project in which I run some Arquillian Tests.

       

      src/main/java/

           com.example.SampleClass

      src/test/java/

           com.example.SampleClassTestWithInjectAnnotation

           com.example.SampleClassTestWithInjectAnnotation2

       

      I created an archive with

       

      ShrinkWrap.create(JavaArchive.class).addPackage(SampleClass.class.getPackage())

       

      The problem is now that all the classes in the package com.example in the archive, all under src/test/java too.

       

      How can I exclude all the classes in the src/test/java directory?

       

      Regards

        • 1. Re: Include package in src/main/java but exclude package in src/test/java
          shonkylogic

          +1 bump. A similar question was asked a year ago, also with no replies. Surely this must be a common requirement?

          • 2. Re: Include package in src/main/java but exclude package in src/test/java
            bmajsak

            Hey guys,

             

            I wouldn't really say it's ShrinkWrap problem per se, as Java basically takes everything under the same classpath... and since we are operating on the class level we are missing this very information from which module classes are comming from. In my humble opinion the best approach would be to simply put your integration tests in different project module and use different namespaces (e.g. package with .test. somewhere), but I understand that this might not be really applicable for all the cases as it always adds some more complexity to the structure, resources files re-use etc.

             

            Anyways, going back to the merrit - since maven compiler puts prod and test classes in dedicated folders, we can leverage that and apply not so perfect, but working approach:

             

            {code:java}

            ShrinkWrap.create(JavaArchive.class, "test.jar")

                            .as(ExplodedImporter.class)

                            .importDirectory("./target/classes/com/acme/product/synchronization/job/")

                            .as(JavaArchive.class);

             

            {code}

             

            You can always merge such jar with your real test archive if necessary.

             

            Not sure if there is any additional filtering besides class name matching though (as pointed out by shonkylogic). Could be interesting case for feature request. Maybe we should raise it on ShrinkWrap Dev forum?

             

            HTH

            • 3. Re: Include package in src/main/java but exclude package in src/test/java
              aslak

              Wondering if we could use Class.getProtectionDomain().getCodeSource().getLocation() for something useful here.

              • 4. Re: Include package in src/main/java but exclude package in src/test/java
                bmajsak

                It's good to learn sth every now and then This should work with Maven way of packaging things. I will raise this concern on ShrinkWrap dev forum right away.