如何在gradle中配置期间防止依赖项解析

时间:2018-11-29 19:51:11

标签: gradle lazy-loading dependency-management

我对Gradle非常陌生。我正在尝试编写两个任务:

  1. 这将提取一些手动下载的档案,并将其放在某个目录中,然后将其发布到存储库中。仅在更新第三方归档文件并且我们需要使用该新版本时才偶尔运行。
  2. 另一个复制任务,这些任务将下载档案,将其解压缩,然后将其复制到本地目录。这应该在编译时运行。 我参与其中,但是似乎在配置时就下载了依赖项,这似乎很奇怪。这意味着什么都没有用,因为我什至无法运行第一个任务,而第二个则无法下载依赖项。

这是到目前为止我得到的:

plugins {
    id 'maven-publish'
}

def mafftGroupId = 'jp.cbrc.mafft'
def mafftArtifactId = 'mafft'
def mafftVersion = '7.388'

def artifactsDir = 'artifacts'
def mafftResourcesDir = 'resources/m2'

// TODO: De-duplicate these
def linux64TarballFile = file("$artifactsDir/mafft-$mafftVersion-linux.tgz")
def linux64TarballArtifact = artifacts.add('archives', linux64TarballFile) {
    classifier = 'linux'
    type = 'tgz'
}
def macZipFile = file("$artifactsDir/mafft-$mafftVersion-mac.zip")
def macZipArtifact = artifacts.add('archives', macZipFile) {
    classifier = 'mac'
    type = 'zip'
}
def win64ZipFile = file("$artifactsDir/mafft-$mafftVersion-win64-signed.zip")
def win64ZipArtifact = artifacts.add('archives', win64ZipFile) {
    classifier = 'win64'
    type = 'zip'
}

publishing {
    publications {
        mafft(MavenPublication) {
            groupId mafftGroupId
            artifactId mafftArtifactId
            version mafftVersion
            artifact linux64TarballArtifact
            artifact macZipArtifact
            artifact win64ZipArtifact
        }
    }

    repositories {
        maven {
            name 'artifactory'
            url 'https://biomatters.jfrog.io/biomatters/libs-release-local'
            credentials {
                username = artifactoryUser
                password = artifactoryPassword
            }
        }
    }
}

// TODO: This should maybe have a type of PublishToMavenRepository but I couldn't figure it out.
task publishMafftToArtifactory {
    dependsOn 'publishMafftPublicationToArtifactoryRepository'
}

configurations {
    mafftArchives
}

dependencies {
    // TODO: Is there a way to just use the artifact files here?
    mafftArchives(group: mafftGroupId, name: mafftArtifactId, version: mafftVersion, classifier: 'linux', ext: 'tgz')
    mafftArchives(group: mafftGroupId, name: mafftArtifactId, version: mafftVersion, classifier: 'mac', ext: 'zip')
    mafftArchives(group: mafftGroupId, name: mafftArtifactId, version: mafftVersion, classifier: 'win64', ext: 'zip')
}

task unpackMafft(type: Copy) {
    // TODO: De-duplicate this too
    configurations.mafftArchives.asFileTree.filter { File f ->
        f.name.endsWith(".zip")
    }.each {
        from(zipTree(it))
    }
    configurations.mafftArchives.asFileTree.filter { File f ->
        f.name.endsWith(".tgz")
    }.each {
        from(tarTree(it))
    }
    rename "mafft-linux64", "Linux64"
    rename "mafft-mac", "OSX"
    rename "mafft-win", "W64"
    into "$mafftResourcesDir"
}

错误是:

FAILURE: Build failed with an exception.

* Where: Build file '/source/trunk/plugins/MafftPlugin/build.gradle' line: 71

* What went wrong: A problem occurred evaluating project ':plugins:MafftPlugin'.
> Could not resolve all files for configuration ':plugins:MafftPlugin:mafftArchives'.
   > Could not find mafft-win64.zip (jp.cbrc.mafft:mafft:7.388).

我想知道是否可以根据运行的任务来确定依赖项的条件,但是据我所知,配置在任何任务图信息可用之前就已经完成。

这让我感到困惑。我不知道该怎么办。

欢呼

0 个答案:

没有答案