Get classpath for gradle project using Android plugin

后端 未结 4 720
旧巷少年郎
旧巷少年郎 2021-01-13 08:55

I\'ve been building some tasks for a gradle multi-project build and have a need to get the class path for a project. The build script has projects that use the Java plugin

4条回答
  •  长情又很酷
    2021-01-13 09:41

    Here is a gradle task that generates the module jar and includes also the test classpath for all variants. It is including libraries and the android.jar from selected runtime.

    I've added two commandline executions for updating some env var inside emacs and for killing any running beanshell (with previous classpath).

    task classpath(type: Jar) {
      from android.sourceSets.main.java.srcDirs,
           android.sourceSets.test.java.srcDirs
      outputs.upToDateWhen { false }
      doLast {
        println "Building classpath..."
        def cp2 = [android.getBootClasspath()[0], it.archivePath]
        android.applicationVariants.all { v ->
          cp2 += v.getApkLibraries()
        }
        def classpath = cp2.unique().join(":")
        println "Updating emacs..."
        exec {
          executable "sh"
          args "-c", "emacsclient --eval '(setenv \"CLASSPATH\" \""+classpath+"\")'"
        }
        exec {
          executable "sh"
          args "-c", "emacsclient --eval '(jdee-bsh-exit)'"
        }
      }
    }
    

    Be aware that I'm using ":" for joining the classpath

提交回复
热议问题