Exclude test folder from maven buildCreate ArrayList from arrayHow can I create an executable JAR with dependencies using Maven?How to add local jar files to a Maven project?IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeExclude Test Classes in dependend Maven JARHow do you “Mavenize” a project using Intellij?Maven is not working in Java 8 when Javadoc tags are incompleteBuilding a maven jar for TestNG automation projectMaven - Wrong folder structureMaven spring-boot ueber-jar and lib

If infinitesimal transformations commute why dont the generators of the Lorentz group commute?

Why is it that I can sometimes guess the next note?

It grows, but water kills it

Why Shazam when there is already Superman?

What was this official D&D 3.5e Lovecraft-flavored rulebook?

Freedom of speech and where it applies

The screen of my macbook suddenly broken down how can I do to recover

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Aragorn's "guise" in the Orthanc Stone

Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed

Yosemite Fire Rings - What to Expect?

The IT department bottlenecks progress. How should I handle this?

Non-trope happy ending?

Melting point of aspirin, contradicting sources

Longest common substring in linear time

How to indicate a cut out for a product window

C++ debug/print custom type with GDB : the case of nlohmann json library

What prevents the use of a multi-segment ILS for non-straight approaches?

Redundant comparison & "if" before assignment

Is there any references on the tensor product of presentable (1-)categories?

Has any country ever had 2 former presidents in jail simultaneously?

Is it possible to put a rectangle as background in the author section?

Why did the Mercure fail?

Open a doc from terminal, but not by its name



Exclude test folder from maven build


Create ArrayList from arrayHow can I create an executable JAR with dependencies using Maven?How to add local jar files to a Maven project?IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeExclude Test Classes in dependend Maven JARHow do you “Mavenize” a project using Intellij?Maven is not working in Java 8 when Javadoc tags are incompleteBuilding a maven jar for TestNG automation projectMaven - Wrong folder structureMaven spring-boot ueber-jar and lib













0















This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?










share|improve this question

















  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20















0















This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?










share|improve this question

















  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20













0












0








0








This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?










share|improve this question














This is one of the most asked questions here in so... but why any answer works for me? i believe i have somehow a wrong maven structure in my project



I have a project like



basedir
|-src
|--many many many packages
|-test
|--testpackages
|-pom.xml


So my pom.xml is in the same level as src and test folders and it isn't the typical structure like java/main/ java/test... it is the root of the project folder



<build>
<sourceDirectory>$basedir/src</sourceDirectory>
<testSourceDirectory>$basedir/test</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>

<configuration>
<source>1.7</source>
<target>1.7</target>
<excludes>
<exclude>**/test/**</exclude>
</excludes>
</configuration>


</plugin>

</plugins>
</build>


but when i run maven install and open the generated jar the folder test is in there...
how can i solve and make it ignore this folder?







java maven






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 4:33









Rafael LimaRafael Lima

494418




494418







  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20












  • 1





    <exclude>test/**</exclude>

    – Micho Rizo
    Mar 8 at 5:20







1




1





<exclude>test/**</exclude>

– Micho Rizo
Mar 8 at 5:20





<exclude>test/**</exclude>

– Micho Rizo
Mar 8 at 5:20












2 Answers
2






active

oldest

votes


















1














Add -DskipTests to mvn command as a workaround. For instance:



mvn package -DskipTests





share|improve this answer























  • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

    – Rafael Lima
    Mar 8 at 4:51











  • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

    – Common Man
    Mar 8 at 5:45











  • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

    – Alok Dubey
    Mar 9 at 4:28












  • @AlokDubey, you are correct.

    – Common Man
    Mar 9 at 4:30


















-1














Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



enter image description here



For more details visit Maven doc






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056770%2fexclude-test-folder-from-maven-build%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests





    share|improve this answer























    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30















    1














    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests





    share|improve this answer























    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30













    1












    1








    1







    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests





    share|improve this answer













    Add -DskipTests to mvn command as a workaround. For instance:



    mvn package -DskipTests






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 8 at 4:37









    Nilanjan BNilanjan B

    2387




    2387












    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30

















    • didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

      – Rafael Lima
      Mar 8 at 4:51











    • @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

      – Common Man
      Mar 8 at 5:45











    • @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

      – Alok Dubey
      Mar 9 at 4:28












    • @AlokDubey, you are correct.

      – Common Man
      Mar 9 at 4:30
















    didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

    – Rafael Lima
    Mar 8 at 4:51





    didn't work... i dont know if i wasn't clear, but the problem is that the test folder is INSIDE the final jar.... is not that maven is running test code

    – Rafael Lima
    Mar 8 at 4:51













    @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

    – Common Man
    Mar 8 at 5:45





    @RafaelLima , if the folder is is final jar then it is already built, how and what you wanna achieve next with maven? Beside all Nilanjan's answer is correct in most cases.

    – Common Man
    Mar 8 at 5:45













    @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

    – Alok Dubey
    Mar 9 at 4:28






    @Common Man: -DskipTests option will skip the test case run only, it won't prevent the test folder from getting packaged if it is at the same level as src and not inside it:(<testSourceDirectory>$basedir/test</testSourceDirectory>)

    – Alok Dubey
    Mar 9 at 4:28














    @AlokDubey, you are correct.

    – Common Man
    Mar 9 at 4:30





    @AlokDubey, you are correct.

    – Common Man
    Mar 9 at 4:30













    -1














    Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



    enter image description here



    For more details visit Maven doc






    share|improve this answer





























      -1














      Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



      enter image description here



      For more details visit Maven doc






      share|improve this answer



























        -1












        -1








        -1







        Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



        enter image description here



        For more details visit Maven doc






        share|improve this answer















        Yes, I believe your maven project structure is not correct. Maven excludes src/test/java for packaging by default so test folder should be inside src and not in the same level as shown below:



        enter image description here



        For more details visit Maven doc







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 9 at 4:36

























        answered Mar 8 at 5:37









        Alok DubeyAlok Dubey

        82211




        82211



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056770%2fexclude-test-folder-from-maven-build%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme