Maven:无法解析pom.xml中的属性

时间:2013-03-27 18:09:25

标签: android maven pom.xml maven-dependency-plugin

我刚刚开始将我的Android项目转换为Maven 我正在尝试在 pom.xml 中使用properties,但我收到错误:

  

未找到依赖项com.google.android:android${android.version}

除了${junit.version}之外,其他属性也遇到了相同的错误 下面是我的 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>

<parent>
    <groupId>org.sonatype.oss</groupId>
    <artifactId>oss-parent</artifactId>
    <version>7</version>
</parent>

<groupId>com.myproject.app</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<modules>
    <module>myapp</module>
    <module>mytests</module>
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <java.version>1.6</java.version>
    <abs.version>4.2.0</abs.version>
    <noa.version>2.4.0</noa.version>
    <junit.version>4.8.1</junit.version>
    <android.version>4.1.1.4</android.version>
    <android-support.version>r12</android-support.version>
    <android.sdk.platform>16</android.sdk.platform>
</properties>


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${android.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>support-v4</artifactId>
            <version>${android-support.version}</version>
        </dependency>
        <dependency>
            <groupId>com.nineoldandroids</groupId>
            <artifactId>library</artifactId>
            <version>${noa.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.3.2</version>
                <configuration>
                    <sdk>
                        <platform>${android.platform}</platform>
                    </sdk>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.8</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.9.1</version>
                <configuration>
                    <failsOnError>true</failsOnError>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.2.2</version>
            <configuration>
                <autoVersionSubmodules>true</autoVersionSubmodules>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.github.github</groupId>
            <artifactId>site-maven-plugin</artifactId>
            <version>0.5</version>
            <executions>
                <execution>
                    <phase>site</phase>
                    <goals>
                        <goal>site</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <message>Creating site for ${project.version}.</message>
                <outputDirectory>website</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

2 个答案:

答案 0 :(得分:1)

它为我提取了依赖项。我建议检查几件事:

  • 运行mvn -X compile以获取有关正在使用哪些镜像的更多信息
  • 检查您的专家settings.xml以查看您正在使用的镜像
  • 确认没有阻止访问存储库的防火墙

答案 1 :(得分:1)

我建议使用androidKickstartR(http://androidkickstartr.com/)创建一个android maven项目,并将pom.xml写入您自己的项目,您可以根据需要对其进行编辑。

准备好时使用以下项目构建项目:

mvn clean install android:deploy