如何使Gradle项目版本友好?

时间:2017-11-22 11:07:47

标签: gradle dependency-management

我有一个Gradle项目,我想导入Versioneye以检查我的依赖项是否是最新的,但它是一个复杂的配置文件(带有外部变量等),而Versioneye不管理正确处理依赖关系。

我不想安装Versioneye gradle插件。

如何将依赖项从我的repo导出到Versioneye?

1 个答案:

答案 0 :(得分:1)

您可以列出所有依赖项gradle app:dependencies

通过一些字符串操作,您可以导出" clean"依赖项文件并手动将其上传到Versioneye。

#!/bin/bash

OUT_DIR='versioneye'
OUT_FILE="${OUT_DIR}/build.gradle"

mkdir -p "${OUT_DIR}"
touch "${OUT_FILE}"

# copy your maven repositories closure below from build.gradle
tee "${OUT_FILE}" <<EOF >/dev/null
allprojects {
    repositories {
        maven {
            url 'https://maven.google.com/maven-google-remote'
        }
        maven {
            url "https://jitpack.io"
        }
    }
}
EOF

echo 'dependencies {' >> "${OUT_FILE}"
./gradlew app:dependencies | grep '^+---' | sed 's|+--- |compile "|' | sed 's| (\*)||g' | sed 's|$|"|' | sort -u >> "${OUT_FILE}"
echo '}' >> "${OUT_FILE}"

cat "${OUT_FILE}"
cd "${OUT_DIR}"
start .
cd -

echo 'Now, open versioneye.com and manually upload the genreated build.gradle file.'

这将生成一个如下所示的文件:

allprojects {
    repositories {
        maven {
            url 'https://maven.google.com/maven-google-remote'
        }
        maven {
            url "https://jitpack.io"
        }
        ...
    }
}
dependencies {
compile "com.android.support.test.espresso:espresso-contrib:2.2.2"
compile "com.android.support.test.espresso:espresso-core:2.2.2"
compile "com.android.support.test.espresso:espresso-intents:2.2.2"
compile "com.facebook.android:facebook-android-sdk:4.17.0"
compile "com.facebook.fresco:fresco:1.5.0"
compile "com.facebook.fresco:imagepipeline-okhttp3:1.5.0"
...
}

此文件可以通过文件上传导入Versioneye,并且可以正确处理。