Skip to content

Maven plugin to reset and initialize compile and test compile source roots of a maven project.

License

Notifications You must be signed in to change notification settings

lengors/init-sources-maven-plugin

Welcome to Init Sources Maven Plugin · GitHub license javadoc Quality Gate Status

Welcome to init-sources-maven-plugin, a plugin that provides a way to reset and set both the compile source roots and the test-compile source roots for any Maven-based project. This allows you to keep the default sourceDirectory and testSourceDirectory properties of the project (usually used by IDEs to enable IntelliSense capabilities) while still allowing for custom source roots, which is especially useful with plugins like the lombok-maven-plugin.

Features

  • Reset source roots: Easily reset your project's compile and test-compile source roots without affecting default configurations.
  • Set custom source roots: Define new source directories for compilation or testing while maintaining existing IDE integrations.
  • Conditional skipping: Skip setting compile or test-compile source roots based on user configurations.

Getting Started

To use the init-sources-maven-plugin, add it to your Maven pom.xml in the build section:

<build>
  <plugins>
    <plugin>
      <groupId>io.github.lengors</groupId>
      <artifactId>init-sources-maven-plugin</artifactId>
      <version>1.0.0</version> <!-- replace with the latest version -->
      <executions>
          <execution>
            <id>default-initSources</id>
            <goals>
              <goal>init-sources</goal>
            </goals>
            <phase>initialize</phase> <!-- Optional -->
        </execution>
      </executions>
      <configuration>
        <compileSourceRoots>
          <compileSourceRoot>generated-sources/generated</compileSourceRoot>
        </compileSourceRoots>
        <testCompileSourceRoots>
          <testCompileSourceRoot>generated-test-sources/generated</testCompileSourceRoot>
        </testCompileSourceRoots>
        <skip>BOTH</skip> <!-- Skip both compile and test source root modification -->
      </configuration>
    </plugin>
  </plugins>
</build>

Replace the version with the latest available, and adjust the configuration parameters based on your project setup.

Usage

The init-sources-maven-plugin can be customized via the following parameters in your pom.xml:

  • compileSources: List of directories to set as the new compile source roots. Example:
<compileSourceRoots>
  <compileSourceRoot>path/to/your/sources</compileSourceRoot>
</compileSourceRoots>
  • testCompileSources: List of directories to set as the new test-compile source roots. Example:
<testCompileSourceRoots>
  <testCompileSourceRoot>path/to/your/test-sources</testCompileSourceRoot>
</testCompileSourceRoots>
  • skip: Controls which source roots are skipped when setting. Can be set to COMPILE, TEST_COMPILE, or BOTH.

Once configured, running the Maven build process will automatically apply the configured source roots:

mvn initialize

Example Scenarios

  1. Using custom directories for both compile and test sources: Specify custom source roots for both main and test source directories, allowing you to set generated or external sources as the project’s root.
<compileSourceRoots>
  <compileSourceRoot>generated/main/java</compileSourceRoot>
</compileSourceRoots>
<testCompileSourceRoots>
  <testCompileSourceRoot>generated/test/java</testCompileSourceRoot>
</testCompileSourceRoots>
  1. Skipping specific source modifications: If you only want to modify one of the source roots (e.g., just compile), you can skip the other:
<skip>TEST_COMPILE</skip>

Documentation and Resources

For detailed guides and additional information, please refer to our GitHub Wiki.

If you wish to check the detailed API documentation, visit the Javadoc page.

Contributing

Contributions are welcome! Please refer to our Contribution Guidelines for more information on how to get involved.

License

This project is licensed under The Unlicense, which places it in the public domain.

About

Maven plugin to reset and initialize compile and test compile source roots of a maven project.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

Languages