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
.
- 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.
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.
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 toCOMPILE
,TEST_COMPILE
, orBOTH
.
Once configured, running the Maven build process will automatically apply the configured source roots:
mvn initialize
- 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>
- 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>
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.
Contributions are welcome! Please refer to our Contribution Guidelines for more information on how to get involved.
This project is licensed under The Unlicense, which places it in the public domain.