Across several projects I have some resources (specifically Flyway database migration scripts) that I'd like to be shared.
Is it possible to have these shared resources exist as a Maven artifact, and prior to a build have Maven resolve that dependency and unpack the contents of the artifact to /src/main/resources/
? If so, how would one go about this?
Add a Java Maven Dependency to the Utility ProjectRight-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.
Maven includes a dependency with this scope in the runtime and test classpaths, but not the compile classpath. This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive.
If you run Maven and it fails to download your required dependencies it's likely to be caused by your local firewall & HTTP proxy configurations. See the Maven documentation for details of how to configure the HTTP proxy.
If you place some files in /src/main/resources
they will be placed on the CLASSPATH in the target JAR artifact. This means if you depend on such an artifact, you will have access to all resources, just as you have access to classes in it.
<dependency>
<groupId>com.example.foo</groupId>
<artifactId>my-resources</artifactId>
<version>0.1</version>
</dependency>
If my-resources
artifact contains some resources in /src/main/resources
, you can access them at runtime just like you (or any other library) can access /src/main/resources
contents from the same artifact.
Note that this won't work with /src/test/resources
because test resources are only placed on CLASSPATH during surefire
execution of current artifact.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With