简体   繁体   English

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

[英]Maven: Cannot resolve property in pom.xml

I just started converting my Android Project into Maven. 我刚刚开始将我的Android项目转换为Maven。
I'm trying to use properties in my pom.xml but I'm getting the error: 我正在尝试在pom.xml中使用properties ,但出现错误:

Dependency com.google.android:android${android.version} not found 找不到依赖项com.google.android:android${android.version}

I'm also getting the same errors for the other properties except for ${junit.version} . 除了${junit.version}之外,其他属性也遇到了相同的错误。
Below is my pom.xml : 以下是我的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>

It fetched the dependencies just fine for me. 它获取了对我来说很好的依赖项。 I suggest checking a few things: 我建议检查一些事情:

  • Run mvn -X compile to get more information about which mirrors are being used 运行mvn -X compile以获得有关正在使用哪些镜像的更多信息
  • Check your maven settings.xml to see which mirrors you are using 检查您的maven settings.xml以查看您正在使用的镜像
  • Verify that there are no firewalls blocking access to the repositories 确认没有防火墙阻止对存储库的访问

I recommend to create a android maven project with androidKickstartR ( http://androidkickstartr.com/ ) and coppy the pom.xml to your own project where you can edit it to your needs. 我建议使用androidKickstartR( http://androidkickstartr.com/ )创建一个android maven项目,并将pom.xml复制到您自己的项目中,然后您可以根据需要对其进行编辑。

When ready build the project with: 准备好使用以下命令构建项目时:

mvn clean install android:deploy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM