gradle:禁止在多项目应用程序的根目录下创建构建文件夹 [英] gradle: disable creation of the build folder at root in multi-projects application

查看:63
本文介绍了gradle:禁止在多项目应用程序的根目录下创建构建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 gradle 项目是一个 multi-project 结构.它由两个子项目组成.我在根项目中的 build.gradle 如下:

My gradle project is a multi-project structure. It consists of two subprojects. My build.gradle in root project as following:

allprojects {
  apply plugin: 'eclipse'
}

subprojects {
  apply plugin: 'java'
  apply plugin: 'maven-publish'

  publishing {
    repositories {
      maven {
        name 'myMaven'
        def suffix = project.version.endsWith("SNAPSHOT") ? "snapshots" : "releases"
        url baseUrl + suffix
      }
    }

    publications {
      core(MavenPublication) {
        artifactId project.name
        artifact jar
      }
    }
  }
}

project(':projectA') {
  ext {
    sharedManifest = manifest {
      attributes("Implementation-Title": project.name,
                 "Implementation-Version": 1.0 )
    }
  }
  jar {
    manifest = project.manifest {
      from sharedManifest
    }
  }
}

project('projectB') {
  ext {
    sharedManifest = manifest {
      attributes("Implementation-Title": project.name,
                 "Implementation-Version": 2.0 )
    }
  }
  jar {
    manifest = project.manifest {
      from sharedManifest
    }
  }
}

gradle build 之后,我得到了三个build文件夹.一个在根目录下,另外两个在各自的子项目中.根项目只是一个没有任何源代码的空文件夹,它只是一个多项目容器.

After gradle build, I got three build folders. one at the root directory and other two in the respective subprojects. The root project is just an empty folder without any source code, it is just a multi-project container.

现在,我不需要创建root build文件夹,因为它没有用.我在网上和gradle docs/forum中搜索,但未获得任何成功.

Now I need to eliminate the creation of root build folder since it is of no use. I search on the net and in the gradle docs/forum but did not get any hit.

有什么办法可以让gradle停止在根级别创建构建文件夹吗?

Is there any way so that gradle stop creating build folder at root level?

推荐答案

谁负责创建 build 目录?

Who is responsible for the build dir creation ?

According to Mark Vieira, a Gradle core dev, each task is responsible for the creation of the ouput dir as long as it creates output.

因此,基本上,您的根项目确实有一个 build 目录,这意味着它不为空,并且有意在其中写入内容.

So basically, it your root project does have a build dir, it means it's not empty and something is deliberately writing into it.

在我的工作中,我正在管理一个由根项目组成的大项目,该项目处理许多 .gradle 文件,设置文件等以及许多带有实际代码的子项目.当我运行 gradle clean build 时,所有子项目都会获得带有libs,binaries等的自己的 build 目录,但根项目最终不会具有任何 build dir,因为任何任务都不会在根 build dir中写入输出.

In my job, I'm managing a big project constituted by a root project, which handles many .gradle files, settings files etc. and many subprojects with the actual code. When I run gradle clean build, all subprojects get their own build dir with libs, binaries etc. but the root project does not end up with any build dir because no task whatsoever writes output in the root build dir.

只需为根项目设置 buildFinished 钩子

Just set up a buildFinished hook only for the root project

gradle.buildFinished {
    project.buildDir.deleteDir()
}

这篇关于gradle:禁止在多项目应用程序的根目录下创建构建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆