代码之家  ›  专栏  ›  技术社区  ›  Ankit Shubham

无法在gradle文件中导入build.gradle以外的第三方类

  •  1
  • Ankit Shubham  · 技术社区  · 7 年前

    我想导入第三方类 org.ajoberstar.grgit.Grgit 在渐变文件中 version.gradle . 但是,它给了我一个错误,即它无法解析org.ajoberstar.grgit.grgit类(我正在使用 apply from: "version.gradle" 内建(gradle)。但如果我把它输入 build.gradle ,它工作得很好。以下是我正在做的:

    build.gradle:

    plugins {
      id "org.ajoberstar.grgit" version "1.5.0"
    }
    apply from: "version.gradle"
    
    // Version of jar file.
    version = 1.0
    
    jar
     {
      destinationDir = file(JAR_DIR)
      from {
        (configurations.runtime).collect {
          it.isDirectory() ? it : zipTree(it)
        }
      }
      manifest {
        attributes 'Main-Class': 'com.awesomeness.Main'
      }
    }
    
    jar.dependsOn versionTxt
    
    // Artifact dependecies.
        dependencies {
          compile files("$TOOLS/lib/grgit-1.5.0.jar")
          compile files("$TOOLS/lib/groovy-all-2.4.7.jar")
          compile files("$TOOLS/lib/org.eclipse.jgit-4.2.0.201601211800-r.jar")
        }
    

    import org.ajoberstar.grgit.Grgit
    //
    import java.text.DateFormat
    
    task versionTxt()  {
        doLast {
            Grgit grgit = Grgit.open()
            File file = new File("$buildDir/version.txt")
            file.write("")
            file.append("Version: $version")
            file.append("Branch: "+grgit.branch.current.trackingBranch.name)
            file.append("Build-Type: ")
            file.append("Build-Date: " + DateFormat.getDateInstance(DateFormat.SHORT).format(new Date((long)grgit.head().time*1000l)))
            file.append("Commit-Id: "+ grgit.head().abbreviatedId)
        }
    }
    

    我尝试了一些这样的链接:

    1 回复  |  直到 7 年前
        1
  •  4
  •   M.Ricciuti    7 年前

    org.ajoberstar.grgit 使用Gradle脚本中可用的包类,使用 buildscript

    version.gradle:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath("org.ajoberstar:grgit:1.5.0")
        }
    }
    import org.ajoberstar.grgit.Grgit
    // .. rest of your build script
    
    推荐文章