Пользовательская папка / путь модульного теста не видит пользовательскую папку / путь src в проекте Maven при использовании терминала - PullRequest
0 голосов
/ 10 января 2019

У меня есть собственная структура в моем проекте

Development -
            -  src
            -  test

и выполнение тестов прекрасно работает через eclipse, но когда я использую терминал на моем mac для запуска теста (mvn test), классы src не обнаруживаются (происходит сбой во время подключаемого модуля компиляции maven). Я полагаю, что это проблема с моим pom, не направляющим плагины в нужные папки. Если я закомментирую эту строку,

 <outputDirectory>Development/build</outputDirectory>

работает нормально, потому что файлы .class теперь помещаются в целевую папку. Вместо того, чтобы смотреть на целевую папку для файлов .class, мне нужно, чтобы maven посмотрел на

Development/build
Каталог

, если я не ошибаюсь. Правильно?

Я хотел бы продолжить использовать мою собственную файловую структуру и исправить мой pom, чтобы он компилировал и запускал модульное тестирование через терминалы моего mac.

<build>
   <sourceDirectory>Development/src/main</sourceDirectory>
   <testSourceDirectory>Development/src/test</testSourceDirectory>
   <plugins>
      <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.5.1</version>
         <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <outputDirectory>Development/build</outputDirectory>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <version>2.3.1</version>
         <configuration>
            <classesDirectory>Development/build</classesDirectory>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-clean-plugin</artifactId>
         <version>3.0.0</version>
         <executions>
            <execution>
               <id>auto-clean</id>
               <phase>clean</phase>
               <goals>
                  <goal>clean</goal>
               </goals>
               <configuration>
                  <filesets>
                     <fileset>
                        <directory>Development/build</directory>
                     </fileset>
                  </filesets>
               </configuration>
            </execution>
         </executions>
      </plugin>
      <plugin>
         <artifactId>maven-assembly-plugin</artifactId>
         <version>3.1.0</version>
         <configuration>
            <descriptors>
               <descriptor>Development/src/assembly/assembly.xml</descriptor>
            </descriptors>
            <tarLongFileMode>posix</tarLongFileMode>
            <executions>
               <execution>
                  <phase>package</phase>
                  <goals>
                     <goal>single</goal>
                  </goals>
               </execution>
            </executions>
         </configuration>
      </plugin>
   </plugins>
</build>

Это вывод консоли

[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ weatherdetails ---
[INFO] Deleting /Users/username/git/weatherdetails/target
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (auto-clean) @ weatherdetails ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ weatherdetails ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/username/git/weatherdetails/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ weatherdetails ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2503 source files to /Users/username/git/weatherdetails/Development/build
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ weatherdetails ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/username/git/weatherdetails/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ weatherdetails ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/username/git/weatherdetails/Development/build
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/username/git/weatherdetails/Development/src/test/com/wfc/schedulers/WeeklySchedulerTest.java:[12,26] cannot find symbol
  symbol:   class WeeklyScheduler
  location: package com.wfc.schedulers

Любые предложения о том, что не настроен правильно?

1 Ответ

0 голосов
/ 11 января 2019

Я смог получить эту работу вскоре после создания этого поста, но хотел посмотреть, есть ли у кого-то другой ответ. При форматировании этого поста, чтобы он соответствовал стандартам stackoverflow, я заметил, что плагин компилятора записывал классы в / Users / имя пользователя / git / weatherdetails / Development / build. я сказал, подождите, это неправильно. он должен записать их в / Users / имя пользователя / git / weatherdetails / Development / build / classes и / Users / имя пользователя / git / weatherdetails / Development / build / test-classes. я погуглил как поменять целевой каталог в поме и наткнулся на этот тег

<directory>Development/build</directory>

Я добавил его в сборку и удалил

<outputDirectory>Development/build</outputDirectory>

тег из плагина компилятора, потому что я добавил его туда, думая, что он создает пользовательскую целевую папку в пути. Запустил его и все заработало. Так что теперь моя сборка выглядит так

<build>
    <sourceDirectory>Development/src/main</sourceDirectory>
    <testSourceDirectory>Development/src/test</testSourceDirectory>
        <!-- if you put just Development, it will erase everything in the development folder -->
        <directory>Development/build</directory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
        <classesDirectory>Development/build</classesDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>auto-clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <configuration>
                            <filesets>
                                <fileset>
                    <directory>Development/build</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <descriptors>       <descriptor>Development/src/assembly/assembly.xml</descriptor>
                    </descriptors>
                    <tarLongFileMode>posix</tarLongFileMode>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </configuration>
            </plugin>
        </plugins>
    </build>

Надеюсь, это кому-нибудь поможет!

...