当前位置: 首页 > 软件库 > 手机/移动开发 > >

multi-module-dependency-setup

授权协议 Readme
开发语言 Kotlin
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 湛铭
操作系统 Android
开源组织
适用人群 未知
 软件概览

Multiple Module Dependency setup ��

The purpose of this repo to demonstrate the use of a custom Gradle plugin to centralize the dependency management in multi-module app setup.

When you start breaking down your Android app into different modules you need to do the following steps for each one:

  • Define compileSdkVersion, buildToolsVersion, minSdkVersion, targetSdkVersion etc.
  • Copy the dependencies block even though you might be repeating yourself. This is specially true for common and test dependencies.
  • Make sure each feature module depends on the app module or whatever base module you have. Turn outs this is a bit of complex scenario to infer for simple use case. This has been removed from the Plugin implementation.

I recently started working on a sample project which demonstrate the use of dynamic-feature modules and found myself in a similar situation.This lead me to do some research on the topic and �� found people already have a solution.There are a couple of blog posts that I found interesting (outlined below) and inspired me to dig further.

About ��

The repo contains two example android modules namely sampleapp and samplelib. These modules demonstrate the usage of the Plugin in their respective build.gradle files here and here.

The, AndroidModulePlugin, plugin will configure the following for each of the modules:

  • compileSdkVersion, buildToolsVersion, minSdkVersion, targetSdkVersion, compileOptions, testInstrumentationRunner
  • Add common test dependencies like junit, mockk
  • Configure SonarQube and its properties
  • Configure Jacoco

Note: You can still override properties which are set by this plugin, by just configuring them again using the android {} or other blocks �� .

Use it in your project ��

The actual setup is pretty simple. The code is also pretty self-explanatory. All you have to do is copy the buildSrc folder to root of your app project.And click on Gradle syncalt gradle sync icon so that gradle can pick up the source and build the plugin and add it to build phase.

After the project builds successfully the only step is to apply the plugin in your individual app/library/feature modules build.gradle.

apply plugin: 'dev.nikhi1.plugin.android'

Make sure to apply this plugin after either application, library and/or dynamic-feature plugin definition in their respective gradle files.

Why Jacoco?

Jacoco is a tool to measure code coverage and currently the most widely used.

Code coverage in simple terms means how much of the production code that you wrote is being executed at runtime when a particular test suite runs.

To measure this you write Unit/UI/Integration tests. And this is what Jacoco does under the hood, it hooks on to these tests while they are executing. In the process, it can see what code is executed as part of the tests and calculates its coverage.These coverages are helpful, for example, if you have miss handling an else branch in one of your test cases.

Though on Android, the test execution data (.ec file) for UI test cases is not taken into account by Jacoco and hence we have to tweak the gradle task and make sure if also reads those files to give a complete code coverage across Unit and UI/Integration test cases.

The task outputs xml reports per module which are uploaded to SonarQube for a nice looking dashboard �� .

This example repo has 100% code coverage. Of course this doesn't mean the code is rock solid and is following all the SOLID principles of software engineering. It's more an indicator that code bases are lacking test cases and we should do something about it �� .

If you are not ready with test cases yet then remove the method configureJacoco from the AndroidModulePlugin class. Every method is self-contained and could be added/removed on need basis.

Why SonarQube?

SonarQube is the leading tool for continuously inspecting the Code Quality and Security of your codebases and guiding development teams during Code Reviews.

These analyses are driven by automated Static Code Analysis rules. You can add your own rules or use detekt rules for analysis as well.

The Plugin configures the different properties required for SonarQube plugin to work properly. For example, the path of the Jacoco xml reports etc. Check here.

This repo uses sonarcloud.io which is free for open-source projects and is a cloud hosted solution. But in most cases, there would be a private hosted SonarQube server running in the infra. Just configure the Plugin with correct values.

Refer this github action if you feel lost.

A word about CI ⚙️

Irrespective of any CI tool, in theory, we need to run some gradle tasks. These gradle tasks are for most cases either run Unit and/or UI tests. Post that some static code analysis which could be either ktlint or detekt or something on similar lines.

Here is the minimum gradle tasks that needs to be run

./gradlew clean connectedDebugAndroidTest jacocoTestDebugUnitTestReport sonarqube

Ofcourse you have to make sure that an emulator/device is up and running in order to run the UI test cases.

If everything is set up properly, you should be able to see the analysis report on the configured SonarQube instance.

Minimum requirements

  • Gradle version: v6.x
  • Android Studio: v4.0

Known limitations

  • Currently there is no way to combine the jacoco reports across different modules. This plugin might help.
  • Cannot skip SonarQube analysis for a particular module.
  • Not tested with Roboelectric framework.

References

 相关资料
  • 我有一个多模块maven项目,它似乎使用org.OWASP:dependency-check-maven插件在父模块和子模块/目标dirs上正确地生成了OWASP依赖关系报告,如下所示: 然而,参考插件文档,并执行sonar-maven-plugin,我只是无法找出正确的命令应该是什么,任何组合似乎都会导致构建失败: mvn声纳:声纳-dsonar.sources=?-dsonar.depende

  • 我正在为下一个项目阅读Spring微服务。Tut说“架构风格主要应用程序分为一组称为微服务的子应用程序。一个大型应用程序分为多个协作过程。”。所以我们已经有了一个框架maven多模块在那里,我在我的经验中分离了项目。即使是。为什么我们需要微服务来分离一个项目?。请区分它。提前感谢…

  • 我正在使用spring Boot将所有旧的单一应用程序转换为共享的微服务。为了帮助维护所有的应用程序,我希望使用位于父目录根目录中的单个gradle文件。我偶然发现了spring boot Multi-Module项目https://spring.io/guides/gs/multi-module/并开始了这条路。 我的问题是,多模块项目是否可以用于共享单个父级gradle文件以及共享库,并且仍然

  • 安装 Maven Repository Elasticsearch Java API包已经上传到 Maven Central 在pom.xml文件中增加: transport 版本号最好就是与Elasticsearch版本号一致。 <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transpo

  • 每个基于Java的应用程序都有一些对象可以协同工作,以呈现最终用户所看到的工作应用程序。 在编写复杂的Java应用程序时,应用程序类应尽可能独立于其他Java类,以增加重用这些类的可能性,并在单元测试时独立于其他类测试它们。 依赖注入(或称为布线)有助于将这些类粘合在一起,同时保持它们独立。 假设您有一个具有文本编辑器组件的应用程序,并且您想要提供拼写检查。 您的标准代码看起来像这样 - publ

  • Dependency Mediator,与Karaf 和其他轻量级模块化技术(类似 osgi,类名不需要是唯一的,但是类名组合和他们定义的 ClassLoader 必须是唯一的)不同,Dependency Mediator 尝试在编译期诊断组件依赖冲突问题,而不是使用自定义的 ClassLoader 来保持不同版本组件的一致性,因此可以有效避免一些臭名昭著的运行期兼容性错误,例如  NoSuchM