MIS – Module Interface Service
Module A exposes SDK (interface + data Model) externally, and registers the corresponding interface service into the service container through the interface when running.
Module B references the SDK exposed by module A and finds the corresponding interface service in the service container through the interface in the SDK and invokes it.
Based on the above, MIS needs to solve the following problems:
- How does a module expose the SDK externally
- How to find the corresponding interface service through the interface
How does a module expose the SDK externally
The SDK described here corresponds to a JAR package, in fact, is the Android Module, hit a jar package containing interface and data model.
How do I find the corresponding service through the interface
Is it ok to maintain a Map with a key interface and a value interface service?
Usage
Reference mis plug-in
Add a reference to the MIS plug-in in the build.gradle of the root project:
buildscript {
dependencies {
classpath 'com. Eastwood. Tools. Plugins: mis: 1.1.0'}}Copy the code
Add the MIS plug-in to the build.gradle module:
apply plugin: 'mis'
Copy the code
Creating the MIS directory
In the SRC /main/ Java sibling directory, create the MIS folder
Define interface and data Model and implement corresponding interface service
Directly in the MIS folder, create the corresponding package name, interface class and data Model (i.e. exposed SDK). And in the Java folder, to achieve the corresponding interface services.
Declare the SDK for the current module
In the module build.gradle dependencies, declare it with misSource, for example:
dependencies {
...
implementation misSource(
group: 'com.eastwood.demo',
name: 'library-sdk'// version: 1.0.0 // Specify the version number when uploading maven)}Copy the code
The registration service
Add the MIS service container library reference to the build.gradle module:
dependencies {
implementation 'mon: com.eastwood.com mis: 1.0.0'
}
Copy the code
The service can then be registered with MisService (service container) using the service interface + the implementation object of the service interface or the implementation class of the service interface, for example:
Misservice.register (ilibraryservice.class, new LibraryService()); // misservice.register (ilibraryservice.class, libraryservice.class);Copy the code
Access to services
Add mis libraries in other modules build.gradle and reference the SDK via misProvider:
dependencies {
implementation 'mon: com.eastwood.com mis: 1.0.0'
implementation misProvider('com.eastwood.demo:library-sdk')}Copy the code
After Sync, MisService can be found in the MisService service container through the interface and invoked, for example:
ILibraryService libraryService = MisService.getService(ILibraryService.class);
libraryService.getLibraryInfo()
Copy the code
Upload the Maven
After interface debugging is complete, package the MIS folder and upload it to Maven.
Configure Maven
Add configuration to build.gradle in the root project or module build.gradle:
apply plugin: 'mis-maven'
misMaven {
username = 'Username'
password = 'password'
repository = 'Repository address on Maven'
snapshotRepository = 'Snapshot repository address on Maven'
}
Copy the code
Configuration GAV
dependencies {
...
implementation misSource(
group: 'com.eastwood.demo',
name: 'library-sdk'Version: 1.0.0 // The version number must be specified when uploading Maven'version-SNAPSHOT')}Copy the code
In addition to mandatory items such as GAV, there are the following configurations:
-
Dependencies String [] type
If the uploaded SDK references other class libraries, you need to configure the corresponding GAV, for example:
dependencies { ... implementation misSource( group: 'com.eastwood.demo', name: 'library-sdk', version: '1.0.0', dependencies = ['com. Google. Code. Gson: gson: 2.8.1'])}Copy the code
Also, configuration under the MicroModule directory structure
dependencies {
...
implementation misSource(
group: 'com.eastwood.demo',
name: 'library-sdk',
version: '1.0.0',
microModuleName: '**microModule name**',
dependencies = ['com. Google. Code. Gson: gson: 2.8.1'])}Copy the code
Executing the upload Task
Open Gradle Tasks View and perform the upload task in the corresponding project.
- publishMis[…] PublicationToMavenRepository corresponding uploaded to the repository
- publishMis[…] PublicationToMavenSnapshotRepository corresponding uploading snapshotRepository
After the upload succeeds, specify or update the version in misProvider.
dependencies {
implementation 'mon: com.eastwood.com mis: 1.0.0'
implementation misProvider('com. Eastwood. Demo: library - SDK: 1.0.0')}Copy the code
QA
1. What if THERE is no Maven private server?
Version in misSource and misProvider is not specified.Copy the code
The last
MIS has been uploaded to Github, welcome star to communicate. Github.com/EastWoodYan…