Я просто собираюсь начать это со ссылок, которые я уже проверил:
Jacoco: IllegalStateException: невозможно добавить другой класс с тем же именем
jacoco: нельзя исключать занятия
Тестовое покрытие JaCoCo: как исключить из отчета класс внутри jar?
JaCoCo Не могу добавить другой класс с таким же именем: org/hamcrest/BaseDescription
Это только ТАК вопросы, которые я проверил, не говоря уже обо всех сообщениях GitHub.
Я потратил 2 полных дня, пытаясь найти решение моей проблемы, но мне еще предстоит найти что-то, что работает.
Итак, история выглядит так:
mvn install:install-file -
Dfile=C:\MavenSelenium\Automation_Framework\src\main\resources\Dependencies\java-api-1.0-jar-with-
dependencies.jar -DgroupId=this.jar.file -DartifactId=api-bundle -Dversion=1.0 -Dpackaging=jar
<dependency>
<groupId>this.jar.file</groupId>
<artifactId>api-bundle</artifactId>
<version>1.0</version>
</dependency>
mvn clean verify
[INFO] --- jacoco-maven-plugin:0.8.6:report (report) @ Automation_Framework ---
[INFO] Loading execution data file C:\MavenSelenium\Automation_Framework\target\jacoco.exec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.851 s
[INFO] Finished at: 2020-12-20T20:35:00+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.6:report (report) on project Automation_Framework:
An error has occurred in JaCoCo report generation.: Error while creating report: Error while analyzing
C:\MavenSelenium\Automation_Framework\target\classes\Dependencies\
java-api-1.0-jar-with-dependencies.jar@org/apache/logging/log4j/core/util/SystemClock.class.
Can't add different class with same name: org/apache/logging/log4j/core/util/SystemClock -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Файл JAR, упомянутый в приведенной выше ошибке, является файлом JAR/зависимостью от моей компании.
Это мой файл pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>Automation_Framework</groupId>
<artifactId>Automation_Framework</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<!-- Selenium Java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- Selenium API -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.141.59</version>
</dependency>
<!-- Selenium Remote Driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.141.59</version>
</dependency>
<!-- Selenium Chrome Driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
<!-- Selenium Common -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-common</artifactId>
<version>2.0b1</version>
</dependency>
<!-- Apache Commons Lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<!-- Video Recorder -->
<dependency>
<groupId>com.automation-remarks</groupId>
<artifactId>video-recorder</artifactId>
<version>1.0</version>
</dependency>
<!-- Apache POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<!-- Apache POI OOXML-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!-- JCraft -->
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
<!-- Extent - RX Java -->
<dependency>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>3.0.4</version>
</dependency>
<!-- Extent - Free Marker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>
<!-- Extent - Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<!-- Extent - GSON -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!-- Apache JMeter Core -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.4</version>
</dependency>
<!-- Apache JMeter Components -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_components</artifactId>
<version>5.4</version>
</dependency>
<!-- Apache JMeter JOrphan -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>jorphan</artifactId>
<version>5.4</version>
</dependency>
<!-- Apache JMeter JUnit -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_junit</artifactId>
<version>5.4</version>
</dependency>
<!-- Apache JMeter HTTP -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_http</artifactId>
<version>5.4</version>
</dependency>
<!-- Apache HTTP Core -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
</dependency>
<!-- XStream Core -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.15</version>
</dependency>
<!-- Aerogear OTP -->
<dependency>
<groupId>org.jboss.aerogear</groupId>
<artifactId>aerogear-otp-java</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Appium Java Client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.4.1</version>
</dependency>
<!-- Company Jar (API) -->
<dependency>
<groupId>this.jar.file</groupId>
<artifactId>api-bundle</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>this.jar.file</groupId>
<artifactId>api-bundle</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Surefire Plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
<!-- Extent - Maven Checkstyle Plugin -->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.16</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<excludes>
<exclude>**/util/SystemClock.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<build>
<plugins>
<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>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<name>Automation_Framework</name>
</project>
Вы заметите, что у меня есть исключение из фактической банки зависимостей для компании, в которой я работаю:
<!-- Company Jar (API) -->
<dependency>
<groupId>this.jar.file</groupId>
<artifactId>api-bundle</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>this.jar.file</groupId>
<artifactId>api-bundle</artifactId>
</exclusion>
</exclusions>
</dependency>
а также в разделе плагинов JaCoCo
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<excludes>
<exclude>**/util/SystemClock.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
ни один из них не работает (по крайней мере, я могу сказать).
Честно говоря, я не понимаю половины «технической беседы», которую я читал, и я уверен, что чем больше я прочитаю за все время, пока я исследую все это, я начну понимать это, НО я не могу дождаться, пока волшебным образом не пойму это, поэтому я надеюсь, что кто-то может помочь.
Я впервые запускаю подобный проект, так что, по общему признанию, мне еще есть чему поучиться.
Зачем добавлять плагин maven-jar? Он уже связан через жизненный цикл по умолчанию и т. д.
Спасибо @khmarbaise за ответы. Честно говоря, я просто не знал ничего лучше, если честно. Как уже упоминалось, это первый раз, когда я создаю подобный проект, и поэтому я учусь по ходу дела. Будет ли слишком много просить вас дать ответ с объяснением проблем и способов их устранения?
Итак, я считаю, что нашел причину своей проблемы.
Насколько я могу судить, это произошло из-за того, как я добавил/сохранил внешний JAR-файл для своей компании.
Файл JAR находился в папке моего проекта:
C:\MavenSelenium\Automation_Framework\src\main\resources\Dependencies\java-api-1.0-jar-with-dependencies.jar
Я удалил файл из этого места И удалил его из списка фактических зависимостей.
Затем я попытался использовать начальную команду из предыдущего, но с файлом, который теперь находится в моей папке загрузок:
mvn install:install-file -
Dfile=C:\Users\{username}\Downloads\java-api-1.0-jar-with-
dependencies.jar -DgroupId=this.jar.file -DartifactId=api-bundle -Dversion=1.0 -
Dpackaging=jar
Однако я не видел, чтобы он появлялся в моих зависимостях.
ТОГДА я щелкнул правой кнопкой мыши папку моих зависимостей (ту, которая по умолчанию создается с проектом maven), и я нажал «Добавить зависимость», как показано ниже:
После того, как я это сделал, я увидел зависимость, добавленную в зависимости, И я увидел, что pom.xml был обновлен с добавлением этой зависимости.
Код добавляется в pom.xml автоматически:
<!-- API -->
<dependency>
<groupId>this.jar.file</groupId>
<artifactId>api-bundle</artifactId>
<version>1.0</version>
</dependency>
Файл jar, который вы установили с помощью файла установки, является так называемым толстым jar-файлом, что означает, что он был создан с учетом нескольких зависимостей (что является очень плохой практикой) и приводит к проблемам. Решение состоит в том, чтобы не использовать такой файл jar. Проблема в том, что вы не можете использовать исключения и т. д. на уровне pom, потому что зависимость не имеет транзитивных зависимостей, и в этом проблема. Помимо проблем в вашем файле pom (использование плагинов в качестве зависимостей, что просто неправильно; определение src/main/java? Почему?) Определение репозиториев в вашем файле pom? Принадлежит вашему файлу settings.xml...