Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 308933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:41:45+00:00 2026-05-12T07:41:45+00:00

I want to run the maven compiler plugin in a different phase and with

  • 0

I want to run the maven compiler plugin in a different phase and with different sourceDirectories and destinationDirectories such that code from directories other than src/main/java and src/test/java can be used.

I thought the solution would look something like the below, where the phase I was linking it to was pre-integration-test. However the properties for testSourceDirectory and testOutputDirectory don’t seem to be specified in this way as they are in the section of the POM.

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

  <executions>
    <execution>
      <id>compile mytests</id>
      <goals>
        <goal>testCompile</goal>
      </goals>
      <phase>pre-integration-test</phase>
      <configuration>
        <testSourceDirectory>${basedir}/src/inttest/java</testSourceDirectory>
        <testOutputDirectory>${basedir}/target/inttest-classes</testOutputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

Is there a way to get this plug-in to compile different directories in different phases without affecting its default operation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:41:45+00:00Added an answer on May 12, 2026 at 7:41 am

    The source directories are set outside the compiler-plugin inside the <build> element, so this won’t work.

    You can use the build-helper-maven-plugin’s add-source and add-test-source to specify additional source directories for your integration tests, but this will not remove the existing source dirs.

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <id>add-it-source</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${basedir}/src/inttest/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    

    If you bind the add-test-source goal to run just before the testCompile goal, your integration tests will be included. Note you want them to be output to target/test-classes so the surefire plugin will find them.

    To handle removal of the standard test sources, I wrote a small plugin to modify the model to remove existing testSource locations before adding the ones for integration tests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run maven-install-plugin before dependency check. How can I do that? The
I want to run maven-replacer-plugin just before packaging war. I have find prepare-package phase
I want to run a Maven compilation by my Java code. Thus, I've used
I want to run some Python unit tests from my Maven module. I have
I've been using tomcat7-maven-plugin. I want to run my webapp which connects to the
I want to run the 'exec-maven-plugin' if a system property is set. How do
I want to run a simple exec command post maven install phase. What is
from maven documentation pluginManagement: is an element that is seen along side plugins. Plugin
i want to run tomcat7 with maven 2 so i tried the maven-t7-plugin with
I want run all script from the directory . Like , The directory contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.