Gradle Multiproject之前构建pushToLocalMaven

时间:2017-10-06 11:46:12

标签: java gradle build.gradle

我有一个由多个java项目组成的gradle项目。假设我们有两个项目,ProjectA和ProjectB。在ProjectB开始编译之前,我想将ProjectA jar发送到本地maven repo。因为ProjectB依赖于ProjectA。我知道我可以分别使用gradle clean build pTMLgradle publishToMavenLocal命令从命令行执行此操作。但是,我想在main build.gradle中执行此操作,而无需一次性执行任何额外步骤。

RootProject
├── ProjectA
│   ├── build.gradle
│   └── src
└── ProjectB
    ├── build.gradle
    └── src

2 个答案:

答案 0 :(得分:0)

您所使用的是复合构建功能,您可以通过&#34; sub-build&#34;替换 class Program { static void Main(string[] args) { int[] uploads = new int[] { 600, 2000, 1000 }; UploadFilesAsync(uploads).ConfigureAwait(true); UploadFilesAsync2(uploads).ConfigureAwait(true); Console.ReadLine(); } public static async Task UploadFilesAsync(IEnumerable<int> uploads) { Console.WriteLine("Start version 1"); uploads.ToList().ForEach(async upload => { Console.WriteLine("Start version 1 waiting " + upload); await Task.Delay(upload); Console.WriteLine("End version 1 waiting " + upload); }); Console.WriteLine("End version 1"); } public static async Task UploadFilesAsync2(IEnumerable<int> uploads) { Console.WriteLine("Start version 2"); foreach (var upload in uploads) { Console.WriteLine("Start version 2 waiting " + upload); await Task.Delay(upload); Console.WriteLine("End version 2 waiting " + upload); } Console.WriteLine("End version 2"); } } 之类的二进制依赖项。这样首先构建项目A,并使用其结果而不是声明的二进制依赖项。您可以在https://docs.gradle.org/current/userguide/composite_builds.html

了解更多相关信息

答案 1 :(得分:0)

我通过向所有子项目添加build.finalizedBy(publishToMavenLocal)命令解决了这个问题。通过这种方式构建项目后,它将直接发布到maven本地存储库。 @Vampire感谢您的帮助,我认为也解决了问题,但这似乎更容易。