使用测试范围时,Maven无法编译测试类

十二烷酸酯

我目前正在尝试使用MockBukkit测试我的Minecraft插件,并将其包含在测试范围中的pom中,因为我只需要这样做但是问题是,当使用测试范围时,依赖关系出现在我的本地存储库中,但是无法通过eclipse或Maven解决。

问题似乎是来自编译器插件的default-compile目标试图编译测试类,即使它不能使用依赖项,因为它们仅在测试阶段可用。(但是,这只是我的猜测)。

Maven的输出:

[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ CityCraft ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 32 source files to C:\Users\lptoa\Desktop\MC Plugins\CityCraft\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[3,32] package be.seeseemelk.mockbukkit does not exist
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[4,32] package be.seeseemelk.mockbukkit does not exist
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[9,17] cannot find symbol
  symbol:   class ServerMock
  location: class test.java.skyvide.de.city.CityTests
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[12,10] cannot find symbol
  symbol:   class Before
  location: class test.java.skyvide.de.city.CityTests
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[19,10] cannot find symbol
  symbol:   class After
  location: class test.java.skyvide.de.city.CityTests
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[15,22] cannot find symbol
  symbol:   variable MockBukkit
  location: class test.java.skyvide.de.city.CityTests
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[16,34] cannot find symbol
  symbol:   variable MockBukkit
  location: class test.java.skyvide.de.city.CityTests
[ERROR] /C:/Users/lptoa/Desktop/MC Plugins/CityCraft/src/test/java/skyvide/de/city/CityTests.java:[22,13] cannot find symbol
  symbol:   variable MockBukkit
  location: class test.java.skyvide.de.city.CityTests

位置:

->src
 --->test
    --->java
      --->example
        --->ExampleTest.java

码:

package test.java.example;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import main.plugin;

public class ExampleTest {
    
    private ServerMock server;
    private Plugin plugin;

    @Before
    public void setUp()
    {
        server = MockBukkit.mock();
        plugin = (Plugin) MockBukkit.load(Plugin.class);
    }

    @After
    public void tearDown()
    {
        MockBukkit.unmock();
    }
}

POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>sv-plugins</groupId>
  <artifactId>CityCraft</artifactId>
  <version>1.0</version>
  <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <profiles>
    <profile>
        <id>testing</id>
        <activation>
            <property>
                <name>test.output.dir</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.3.1</version>
                    <configuration>
                      <outputDirectory>${test.output.dir}</outputDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
  </profiles>
  <repositories>
    <repository>
        <id>papermc</id>
        <url>https://papermc.io/repo/repository/maven-public/</url>
    </repository>
    <repository>
        <id>spigot-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
    <repository>
        <id>everything</id>
        <url>https://repo.citizensnpcs.co/</url>
    </repository>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
    <repository>
        <id>aikar</id>
        <url>https://repo.aikar.co/content/groups/aikar/</url>
    </repository>
  </repositories>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <artifactSet>
                        <includes>
                            <include>com.github.WesJD.AnvilGUI:anvilgui</include>
                            <include>co.aikar:acf-paper</include>
                        </includes>
                    </artifactSet>
                </configuration>
            </execution>
        </executions>
      </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
  </build>
  <dependencies>
  <dependency>
    <groupId>com.destroystokyo.paper</groupId>
    <artifactId>paper-api</artifactId>
    <version>1.15.2-R0.1-SNAPSHOT</version>
    <scope>provided</scope>
 </dependency>
  <dependency>
    <groupId>net.citizensnpcs</groupId>
    <artifactId>citizens</artifactId>
    <version>2.0.27-SNAPSHOT</version>
    <type>pom</type>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>sv-plugins</groupId>
    <artifactId>MySQL</artifactId>
    <version>1.0</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>sv-plugins</groupId>
    <artifactId>Clouds</artifactId>
    <version>1.0</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>com.github.WesJD.AnvilGUI</groupId>
    <artifactId>anvilgui</artifactId>
    <version>master-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>co.aikar</groupId>
    <artifactId>acf-paper</artifactId>
    <version>0.5.0-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>com.github.seeseemelk</groupId>
    <artifactId>MockBukkit-v1.16</artifactId>
    <version>0.5.0</version>
    <scope>test</scope>
  </dependency>
  </dependencies>
</project>
十二烷酸酯

好的,错误是我不得不更改.classpath,因为我只是将默认的eclipse项目转换为Maven项目,所以我不得不在Build Path中删除默认的src文件夹,并添加其他Maven文件夹。没有它,Maven尝试将每个类编译为普通类,而不是将其失败的测试。

如果有人感兴趣,这里是两个.classpath文件之间的比较:

旧:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
        <attributes>
            <attribute name="module" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

新:

<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
        <attributes>
            <attribute name="module" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="src/main/resources"/>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

测试时部署Maven

来自分类Dev

无法使用 testNG、maven、NetBeans 仅从一个类运行我的测试

来自分类Dev

Maven无法从其他模块中找到测试超类

来自分类Dev

在其他模块中使用测试范围中的类

来自分类Dev

使用Selenium时Tomcat无法编译类

来自分类Dev

Python单元测试,使用基本测试类时跳过测试

来自分类Dev

无法使用unittest修补由测试的类实例化的类

来自分类Dev

使用qtest和quickcheck,无法编译测试代码

来自分类常见问题

使用@testable时,“未编译模块进行测试”

来自分类Dev

使用 youtube API 编译测试项目 xamarin 表单时出错

来自分类Dev

使用Maven surefire插件运行多个测试类

来自分类Dev

使用 maven (mvn test) 执行 TestNG 测试时 Maven 跳过测试

来自分类Dev

Maven无法运行特定测试

来自分类Dev

无法从Maven运行黄瓜测试

来自分类Dev

无法从Maven运行黄瓜测试

来自分类Dev

Maven无法识别junit测试

来自分类Dev

maven 不编译测试代码/不运行测试代码

来自分类Dev

Maven测试类如何访问源类

来自分类Dev

使用Spock和Maven在单个测试类中运行特定的测试

来自分类Dev

如何从包阶段排除Maven测试范围?

来自分类Dev

无法使用testNG和Allure在TeamCity中从Maven运行测试

来自分类Dev

编译的DLL中的测试方法和测试类

来自分类Dev

编写Tester类以测试编译的文件

来自分类Dev

无法使用gradle按类别包括/排除Junit测试类

来自分类Dev

WebDriver。使用参数化类后无法运行测试

来自分类Dev

测试Card和CardCollection类时使用GoogleMock避免依赖

来自分类Dev

测试公共类时使用未解析的标识符

来自分类Dev

Grails错误编译单元测试-无法解析应用程序类

来自分类Dev

使用Jest运行测试时无法使用uuid模块

Related 相关文章

热门标签

归档