maven включает testOutputDirectory в банке - PullRequest
0 голосов
/ 24 апреля 2019

Хотите добавить файлы testoutputdirectory в jar проекта. Пробовал с использованием ниже, но тестовые классы не были включены в банку

Что нужно изменить, чтобы включить то же самое в банку проекта?

Использование ниже в pom.xml

<build>
    <finalName>${project.name}</finalName>
    <testOutputDirectory>test/classes</testOutputDirectory>
    <resources>
            </resources>

    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <finalName>${final.name}</finalName>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
                <descriptor>./src/main/resources/assembly/assembly.xml</descriptor>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>   

     .........
</build>

Ниже у меня в Assembly.xml

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0         http://maven.apache.org/xsd/assembly-2.0.0.xsd">

<moduleSets>
    <moduleSet>
        <sources>
            <fileSets>
                <fileSet>
                    <directory>.</directory>
                    <outputDirectory>/</outputDirectory>
                    <includes>
                        <include>test/classes/**/*.class</include>
                    </includes>
                </fileSet>
            </fileSets>
        </sources>
    </moduleSet>
</moduleSets>
</assembly>

Ответы [ 2 ]

1 голос
/ 25 апреля 2019

Не думаю, что это вообще хорошая идея. Возможно, подумайте о создании отдельного тест-кувшина. Вы можете сделать это с помощью цели maven-jar-plugin test-jar

Тем не менее, если вы действительно хотите это сделать, вы можете добиться этого, установив testOutputDirectory нравится:

<build>
    <testOutputDirectory>${project.build.directory}/classes</testOutputDirectory>
</build>

Затем Tests.java компилируется в target / classes и оттуда maven-jar-plugin упаковывает их в jar.

0 голосов
/ 25 апреля 2019

Спасибо всем за вашу помощь.

Мне удалось включить каталог testoutput в jar, используя приведенное ниже.

<build>
    <finalName>${project.name}</finalName>
    <testOutputDirectory>test/classes</testOutputDirectory>
    <resources>

           </resources>
    <plugins>
                      <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <finalName>${final.name}</finalName>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
                <descriptors>
                    <descriptor>src/main/resources/assembly/assembly.xml</descriptor>
                </descriptors>
                <!-- descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs-->
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
      .......
     </plugins>
     ..........
</build>




<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">

<id>jar-with-dependencies</id>
<baseDirectory>/</baseDirectory>
<formats>
    <format>jar</format>
</formats>
<fileSets>
    <fileSet>
        <directory>./target/classes/</directory>
        <outputDirectory></outputDirectory>
        <includes>
            <include>**/*.class</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>.</directory>
        <outputDirectory></outputDirectory>
        <includes>
            <include>test/classes/**/*.class</include>
        </includes>
    </fileSet>
</fileSets>    
<dependencySets>
    <dependencySet>
        <useProjectArtifact>false</useProjectArtifact>
    </dependencySet>
</dependencySets>
</assembly>
...