0

I'm trying to get maven to copy some resources (specifically a master.css file) from a Core module into all modules that depend on it.

I'm attempting to use the first answer on this question: Use a dependency's resources? :

<build>
        <plugins>
            <!--Extract core's resources-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>${project.groupId}</includeGroupIds>
                            <includeArtifactIds>core</includeArtifactIds>
                            <excludeTransitive>true</excludeTransitive>
                            <overWrite>true</overWrite>
                            <outputDirectory>${project.build.directory}/core-resources</outputDirectory>
                            <excludes>org/**,META-INF/**,rebel.xml</excludes>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <!--New resource locations-->
        <resources>
            <resource>
                <filtering>false</filtering>
                <directory>${project.build.directory}/core-resources</directory>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
    </build> 

I put this code in the pom.xml file for Core (not the parent project -- is that right?)/ But I'm having trouble with it -- I am unsure I'm doing everything correctly. I do not see anything copied over in the target directories of the modules that depend on Core.

Here is the output of that part when I mvn clean install:

--- maven-dependency-plugin:2.1:unpack-dependencies (unpack) @ Core ---

--- maven-resources-plugin:3.0.2:resources (default-resources) @ Core ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory {project-directory}\Core\target\core-resources
Copying 16 resources

where {project-directory} is the full path to my project.

My core resources folder looks like this:

src/main/resources
    /core-resources
        master.css
    /fxml
        ~some stuff~
    /imgs
        ~some stuff~
    /styles
        ~some stuff~

I do not see anything copied over in the target directories of the modules that depend on Core.

Basically, I have 3 questions:

Where is it copying from?

Where is it copying to?

Why isn't it copying anything right now?

If there's any other information that's needed I can provide that. I'm not very good at maven and honestly the maven docs are Greek to me. I'm probably misunderstanding something important about maven so if something sounds weird please tell me.

MattT
  • 33
  • 4
  • how do your modules express dependencies on **core**? Is **core** listed in `` of the projects that depend on it? If it is multimodule project with parrent/children, then just use `..\core\src\main\resources` from dependant children. – diginoise Jul 09 '18 at 15:45

1 Answers1

0

Where is it copying from?

your worries come from PATH :

<build>
    <plugins>
        <!--Extract core's resources-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                    <configuration>
                        <includeGroupIds>${project.groupId}</includeGroupIds>
                        <includeArtifactIds>core</includeArtifactIds>
                        <excludeTransitive>true</excludeTransitive>
                        <overWrite>true</overWrite>
                        <!-- HERE -->
                        <outputDirectory>${project.build.directory}/core-resources</outputDirectory>
                        <excludes>org/**,META-INF/**,rebel.xml</excludes>
                        <overWriteReleases>true</overWriteReleases>
                        <overWriteSnapshots>true</overWriteSnapshots>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <!--New resource locations-->
    <resources>
        <!-- AND HERE -->
        <resource>
            <filtering>false</filtering>
            <directory>${project.build.directory}/core-resources</directory>
        </resource>
        <resource>
            <filtering>false</filtering>
            <directory>${basedir}/src/main/resources</directory>
        </resource>
    </resources>
</build> 

Where is it copying to?

he tries to copy in **/core-resources

Why isn't it copying anything right now?

He tries to read in the following package **/core-resources

Another is correctly out of plugin version it's

<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>

PS: Sorry for me english.

jguyet
  • 75
  • 8
  • So what do I need to change? I have master.css in Core/src/main/resources/core-resources. I want to access master.css in a module that depends on Core. – MattT Jul 09 '18 at 15:46
  • if your master.css is in your resource path the content of this is copied to dest outputDirectory. – jguyet Jul 09 '18 at 15:48
  • I don't see it copied anywhere. I open [Module that depends on Core]/target/classes and don't see core-resources. – MattT Jul 09 '18 at 16:05