Question: how to use maven resource filtering?
See original GitHub issueHello,
Let me say it’s a great project and it’s a real pleasure to use in our development life cycle.
However, I’m having a hard time with one particular use case. I’m not particular sure whether it’s the right place to ask question. Please forward me to right place if it is not.
The question: How does one use properly maven resource filtering capability? I’ve found mentioning of assembly filter flag in some other issues. I’ve tried, but I kinda failed / didn’t like the result.
Let me explain my use case first:
- I have Docker file
ADD
-ing some configuration file fromsrc/main/docker
- That particular file contains artifactId and artifact version.
- I would like to have that information to be provided / injected by maven resource filtering.
What I’ve tried:
- Assembly
<fileSet>
, which took the original file and placed it somewhere attarget/docker/registry-xyz.com/artifact/0.0.1-SNAPSHOT/build/maven/home/username/path1/path2/target/docker/registry-xyz.com/artifact/0.0.1-SNAPSHOT/build/maven/MY_FILE
I’m struggling to find the proper workaround and come up with concise and clear configuration snippet to get it done.
Any suggestions, maybe some links to examples or documentation etc … I would really appreciate that…
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Apache Maven Resources Plugin – Filtering
Filtering. Variables can be included in your resources. These variables, denoted by the ${...} delimiters, can come from the system ...
Read more >Maven resource filtering for single file - Stack Overflow
Now the problem is all xml files are not filtered. Is there any possible way to filter single xml file? xml · spring...
Read more >Using Maven properties as Mule properties - Medium
The method is called resource filtering, and is provided by the Maven Resources plugin. It looks for placeholders in the resources folders. By ......
Read more >9.3. Resource Filtering - TheNEXUS | A Community Project
Using Maven resource filtering you can reference Maven properties and then use Maven profiles to define different configuration values for different target ...
Read more >Intellij make build maven resources filtering
If I compile the android app using maven directly "mvn clean package", resource filtering is applied successfully to my final apk. If I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @leonardinius @vberruchon,
below is my answer (similar to @chris-snider):
First, let’s make sure our plugin versions are properly defined in the
<pluginManagement>
section:Step 1: setup
maven-resources-plugin
:Note: the
<outputDirectory>${project.build.directory}/docker</outputDirectory>
is important for 2 reasons a) when you do custom resource filtering you should always send the filtered (modified) resource to the build output directory (${project.build.directory}
) as good practice, and b) this acts as theDockerfile
input for the Docker maven plugin belowStep 2: setup
docker-maven-plugin
:You can now add Maven variable interpolation
${...}
inside yoursrc/main/docker/Dockerfile
, for example I do something like:using properties such as:
Setting
<dockerFileDir>${project.build.directory}/docker</dockerFileDir>
makes my build fail withExecution docker of goal io.fabric8:docker-maven-plugin:0.15.16:build failed: A tar file cannot include itself.
probbably beacuse it causes the docker-build.tar to reference itself. When I open the tar it has aDockerfile
at root, amaven
directory, and a directory structure corresponding to the docker repository withtmp
,build
andwork
folders.