The collection of all maven parent sources

Part of the results for the client includes the source code of the project we are working on. I am using maven with mvn generate-sources. The problem is that it includes all the dependencies and aggregates the sources for the dependency. I am trying to create a flat structure with .javafiles filtered on groupid.

The documentation is very biased by maven-source-plugin . All the search queries that I do indicate me filtering resources, which I am not looking for.

The structure of my project is the parent pom with the children, and I am trying to achieve something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
    <resouces>
            <filter>
                    <include>com.mygroupid.project</include>
            </filter>
    </resouces>
</plugin>

What I expect:

  • The "fat" structure (all project sources aggregated by package name in one directory)
  • No duplicate sources

Edit:

​​:

- module-1 pom.xml  // aggregate project
    |- module-1-core (has dependency to module-2 and module-2)
    |- module-1-war
- module-2 pom.xml  // aggregate project
    |- module-2-commons
- module-3 pom.xml  // aggregate project
    |- module-3-services
- // etc...

:

- big-fat-code-sources.zip
    |- module-1-core sources + test source
    |- module-1-war sources + test source
    |- module-2-commons sources + test source
    |- module-3-services sources + test source
    |- // etc...
+4
2

source:aggregate :

mvn clean source:aggregate

,

- root pom.xml  // aggregate project
  |- module1 // jar module
  |- module2 // another jar...

pom:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>3.0.1</version>
</plugin>

.jar target, modules, .

doc Maven.

+1

maven-assembly-plugin .

assembly.xml :

<moduleSets> // 1
    <moduleSet>
        <includes>
            <include>mrkrabs-secret-recipe:*</include>
        </includes>
        <useAllReactorProjects>true</useAllReactorProjects>
        <sources>
            <outputDirectoryMapping>${artifactId}-${version}</outputDirectoryMapping> // 2
            <includeModuleDirectory>true</includeModuleDirectory>
            <fileSets>
                <fileSet> // 3
                    <directory>src</directory>
                    <excludes>
                        <exclude>**/target/**</exclude>
                        <exclude>**/bin/**</exclude>
                    </excludes>
                </fileSet>
            </fileSets>
        </sources>
    </moduleSet>
</moduleSets>
  • maven

.

, :

<dependencySets> // 1
    <dependencySet>
        <includes> // 2
            <include>mrkrabs-secret-recipe:*</include>
        </includes>
        <scope>provided</scope>
        <outputDirectory>/dependencies</outputDirectory> // 3
        <useTransitiveFiltering>true</useTransitiveFiltering> // 4
        <unpack>true</unpack>
        <unpackOptions> // 5
            <includes>
                <include>mrkrabs-*/**</include>
            </includes>
            <excludes>
                <exclude>*.sql</exclude>
                <exclude>*.zip</exclude>
                <exclude>*.class</exclude>
                <exclude>*.jar</exclude>
            </excludes>
            <useDefaultExcludes>true</useDefaultExcludes>
        </unpackOptions>
    </dependencySet>
</dependencySets>
  • maven
  • mrkrabs
  • /
  • :

    • mrkrabs (useTransitiveFiltering , )
    • , (.sql,.zip,.class,.jar)
0

Source: https://habr.com/ru/post/1694974/


All Articles