how to use maven plugin to copy source dir to a target folder

3,073 views
Skip to first unread message

Biswa

unread,
Feb 17, 2020, 8:32:58 AM2/17/20
to DevOpsSchool Support
I have a source directory as   foo.

Under foo, I have few files and sub directories. These files are just text files and html files and not part of the compiled code (my project is in Java).

 During build, I want maven to create a target dir as   "foo/output" and copy all the contents of foo/* to foo/output.

I tried the following but it does not work; meaning mvn install does not even create the output or target directory.

Appreciate your help!

                <build><plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <id>copy-helm-to-target</id>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${basedir}/output</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>foo</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin></build>

Biswa

unread,
Feb 17, 2020, 10:09:52 AM2/17/20
to DevOpsSchool Support
Missed to say that, I do not have any   foo/pom.xml. This dir does not have any compiled code and hence no pom.xml.
So I am trying to add the above plugin in parent pom.

Parag Patil

unread,
Feb 17, 2020, 10:20:31 AM2/17/20
to Biswa, DevOpsSchool Support
Have you tired using  <artifactId>maven-war-plugin</artifactId> ??

Thanks
-Parag


--
You received this message because you are subscribed to the Google Groups "DevOpsSchool Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to devopssuppor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/devopssupport/6cc72d08-48c0-45be-995d-0615b9b08002%40googlegroups.com.

Biswa

unread,
Feb 17, 2020, 10:47:44 AM2/17/20
to DevOpsSchool Support
Hi Parag!
As I said, foo/* does not contain any real source code. There is nothing under foo/* to be compiled. So why to use war-plugin? I don't want any wa or an deliverable / artifact to be built.
All I want is copy the files/dirs from foo. This is a requirement even before my actual build stage in my pipeline.

As a requirement I am modifying the files under foo/target during Build stage,    Copying these to target and modifying will help Git to ignore these target/output directory files after the build.
Without this, developer can accidentally check-in these files!

Note that, I am able to achieve this with a child pom , as foo/pom.xml. But I am unable to achieve it only with the parent pom.
To unsubscribe from this group and stop receiving emails from it, send an email to devops...@googlegroups.com.

Darvin Chaudhary

unread,
Feb 18, 2020, 12:40:58 AM2/18/20
to Biswa, DevOpsSchool Support
Biswa,

You can do it anytime(before or after build) in any stage by normal shell commands. Why you want to use just maven for it? 

If you still want to copy then you can use some dependency plugin.


Kindly have a look on:
dependency:copy
dependency:copy-dependencies

They can do many tasks without writing any code like renaming, stripping versioning etc.😉

Regards,
Chaudhary Darvin



To unsubscribe from this group and stop receiving emails from it, send an email to devopssuppor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/devopssupport/efaf0b29-a973-4083-8c11-47c323a61a73%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages