gpt4 book ai didi

android - Eclipse:为什么以及何时在使用 Maven 项目时将库添加到构建路径而不会有有缺陷的 Eclipse 项目?

转载 作者:行者123 更新时间:2023-11-30 02:52:06 24 4
gpt4 key购买 nike

我在 Eclipse 中有一个由 Maven 管理的 Android 项目。昨天我通过Eclipse中的“Checked for Updated”功能升级了Eclipse和一些插件。更新完成后,我的 Android 项目有缺陷。首先,我认为这只是一个“清理/更新项目/Maven 重建”问题,或者库的包含顺序可能不再合适(例如,Maven 依赖项不在顶部或类似的东西),但我是能够通过 Maven 构建,因此没有项目或 Maven 问题,而是 Eclipse 问题。为了让它再次工作,我必须手动将 Maven 存储库中的 Hamcrest、Junit 和 Mockito 添加到构建路径中。在这个项目中我之前不必这样做(android-4.1.1.4.jar 除外)。我想了解什么时候以及为什么我突然必须这样做? (在早期的项目中,我还必须手动添加一些外部库)。

(我总是通过clean install android:deploy android:run来构建和我的项目。)

Eclipse

这是我目前安装的一些重要插件... enter image description here

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mydomain</groupId>
<artifactId>myapp</artifactId>
<packaging>apk</packaging>
<version>1.0-SNAPSHOT</version>
<name>My App</name>
<url>http://maven.apache.org</url>

<properties>
<platform.version>2.2.1</platform.version>
<android.sdk.path>/opt/android-sdk-linux</android.sdk.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junit.version>4.8.2</junit.version>
<mockito.version>1.9.5</mockito.version>
<jackson.version>1.9.13</jackson.version>
<hamcrest.version>1.3</hamcrest.version>
<android.version>4.1.1.4</android.version>
<annotations.version>4.1.1.4</annotations.version>
<supportv4.version>r13</supportv4.version>
</properties>

<repositories>
<repository>
<id>codehaus</id>
<url>http://repository.codehaus.org/org/codehaus</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${android.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>${supportv4.version}</version>
</dependency>
<!-- LInt Annotations -->
<dependency>
<groupId>com.google.android</groupId>
<artifactId>annotations</artifactId>
<version>${annotations.version}</version>
</dependency>

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- Non Android Tests --><!-- hamcrest must be before JUnit due to build errors -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.1</version>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.1</version>
</dependency>


</dependencies>

<build>
<outputDirectory>bin/classes</outputDirectory>
<testOutputDirectory>bin/test-classes</testOutputDirectory>

<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sign>
<debug>true</debug>
</sign>
<sdk>
<platform>13</platform>
<path>${android.sdk.path}</path>
</sdk>
<undeployBeforeDeploy>false</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<versionRange>[3.2.0,)</versionRange>
<goals>
<goal>manifest-update</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</build>
</project>

这是错误日志的输出
enter image description here

**问题是它没有找到类(直到我手动导入它,但 Maven 和 Eclipse 应该处理)如果我尝试导入例如 org.junit.Test , org.junit.runner.RunWithorg.mockito.Mock 我进入 Eclipse

The import xxxxx cannot be resolved

Eclipse 中的问题选项卡:

The project was not built since its build path is incomplete. Cannot find the class file for org.mockito.verification.VerificationMode. Fix the build path then try building this project com.mygame-TRUNK Unknown Java Problem The type org.mockito.verification.VerificationMode cannot be resolved. It is indirectly referenced from required .class files GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game line 1 Java Problem

最佳答案

从版本 1.0.0 开始 Android for Maven Eclipse改变了它管理 Maven 类路径的方式。非运行时依赖项(实际上,任何不在 compile 范围内的东西)现在都被加载到一个新的 Maven 非运行时类路径容器中。您看到这些库出现在这个新的类路径容器中了吗?

如果没有,请尝试从您的工作区中删除该项目,删除特定于 IDE 的 .* 元数据文件并尝试重新导入为 Maven 项目。

关于android - Eclipse:为什么以及何时在使用 Maven 项目时将库添加到构建路径而不会有有缺陷的 Eclipse 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23977715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com