在Maven(pom.xml)和Gradle(build.gradle)之间共享依赖项版本

时间:2018-09-27 22:01:30

标签: maven gradle dependency-management

我有Maven和Gradle构建的项目。有没有一种方法可以在文本文件中定义依赖项版本,例如:

class Test
{
    const TOP_SIDE = 'a';
    const BOTTOM_SIDE = 'b';
    const HORIZONTAL_SIDES = self::TOP_SIDE . self::BOTTOM_SIDE;

    const LEFT_SIDE = 'c';
    const RIGHT_SIDE = 'd';
    const VERTICAL_SIDES = self::LEFT_SIDE . self::RIGHT_SIDE;

    const ALL_SIDES = self::HORIZONTAL_SIDES . self::VERTICAL_SIDES;


    public function makeTest($sideType)
    {
        if($this->containsSide($sideType, self::TOP_SIDE)) {
            echo 'a';
        }

        if($this->containsSide($sideType, self::BOTTOM_SIDE)) {
            echo 'b';
        }

        if($this->containsSide($sideType, self::LEFT_SIDE)) {
            echo 'c';
        }

        if($this->containsSide($sideType, self::RIGHT_SIDE)) {
            echo 'd';
        }
    }

    private function containsSide($sideType, $singleSide)
    {
        return false !== strpos($sideType, $singleSide);
    }
}

$test = new Test();
$test->makeTest(Test::ALL_SIDES);

是否有一种简单的方法可以在. |-- dep-versions.properties | |-- proj-by-gradle | |-- build.gradle | `-- settings.gradle | `-- proj-by-maven `-- pom.xml 中进行指定,例如:

dep-versions.properties

然后在com.google.guava:guava = 26.0-jre org.apache.commons:commons-pool2 = 2.5.0 pom.xml中使用这些版本?

1 个答案:

答案 0 :(得分:2)

您可以创建BOM表pom(物料清单)并在两个版本中使用它。在4.6版中,已将对导入Maven BOM文件的支持添加到了Gradle:https://docs.gradle.org/4.6/release-notes.html#bom-import