gradle 练习项目
gradle学习总结 buildSrc 插件引入和打包发布到其他项目插件引入不同
buildSrc和app是同一个工程新的插件编写不能在buildSrc目录下,会出现错误
id 'com.imooc.router'
其他项目 id 'com.imooc.router.router-gradle-plugin' version '1.0.0' apply false
apply plugin: 'com.imooc.router'插件名称 和 com.imooc.router.properties 要一致
apply plugin: 'maven' , 如果你项目的gradle版本>7.0,在项目中引用maven插件
报错如下:
Plugin with id 'maven' not found.
因为在In Gradle 7.x官网已经废弃了
解决方案:
https://www.jianshu.com/p/cc21c1aa1a2a
Build was configured to prefer settings repositories over project repositories but repository ' MavenRepo' was added by build file 'router-gradle-plugin/build.gradle'
在插件里不用声明
//repositories {
// mavenCentral()
//}
这个已经已经在settings中声明过了
./gradlew router-gradle-plugin:publish 发布插件到本地仓库
plugins {
id 'com.imooc.router:router-gradle-plugin:1.0.0'
}
报错如下
plugin id 'com.imooc.router:router-gradle-plugin:1.0.0' is invalid: Plugin id contains invalid
char ':' (only ASCII alphanumeric characters, '.', '_' and '-' characters are valid)
id 只能是字母 . _ - 不包含数字
解决方案:
id 'com.imooc.router'
gradle 6.0版本发布 和编写插件
apply plugin: 'groovy'
apply plugin: 'maven'
repositories {
mavenCentral()
}
dependencies {
//xxx
}
uploadArchives{
// 打包成一个jar 引用jar 生成这个三个信息
repositories.mavenDeployer {
//项目名
pom.groupId = 'com.x'
pom.artifactId = 'modify'
pom.version = '1.0.0'
repository(url: uri('../repo'))
}
}
sourceCompatibility = "8"
targetCompatibility = "8"
https://blog.csdn.net/weixin_41733225/article/details/140108271
gradle 7.0版本发布 和编写插件
//maven插件在gradel7.0 已删除
apply plugin: 'groovy'
apply plugin: 'maven-publish'
// 或者以下写法
//plugins {
// id 'groovy'
// id 'maven-publish'
//}
dependencies {
//......略写
}
afterEvaluate {
publishing {
// 配置maven-publishing插件的输出物
publications {
maven(MavenPublication) {
groupId = 'com.x'
artifactId = 'modify'
version = '1.0.0'
}
}
repositories {
maven {
url = uri('../repo')
}
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
gradle 8.0版本发布 和编写插件
这行代码很重要,才能把jar包打入
from components.java
publishing {
publications {
maven(MavenPublication) {
groupId 'com.example'
artifactId 'app-start-counter'
version '1.0.0'
from components.java
}
}
repositories {
maven {
url "
credentials {
username 'your-username'
password 'your-password'
}
}
}
}
取代gradle6.0 resources/META-INF/xxxxx.properties配置 下面代码: group = 'com.imooc.router' version = '1.0.0'
gradlePlugin {
plugins {
//MyTestPlugin { //这种方式也行
create("RouterPlugin") {
//插件id
id = 'com.imooc.router.router-gradle-plugin'
//插件的包名+类名
implementationClass = 'com.imooc.router.gradle.RouterPlugin'
}
}
}
android2024 gradle8 Processor和ksp两种编译时注解实现
发现在高版本的gradle上以前的Transform已经废弃,下面如何在高版本适配
Android Gradle8.0 Transform 废弃如何适配,手撸Arouter插件教你使用
Transform废弃,有部分类找不到了TransformManager
groovy 目录下面不能放kotlin/java不会编译,导致插件类找不到
android 子项目 和java项目 发布是不一样的 // 指定要发布的构件 artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
Reason: Task ':runter-runtime:publishMavenPublicationToMavenRepository' uses this output of task ':runter-runtime:bundleDebugAar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Possible solutions:
1. Declare task ':runter-runtime:bundleDebugAar' as an input of ':runter-runtime:publishMavenPublicationToMavenRepository'.
2. Declare an explicit dependency on ':runter-runtime:bundleDebugAar' from ':runter-runtime:publishMavenPublicationToMavenRepository' using Task#dependsOn.
3. Declare an explicit dependency on ':runter-runtime:bundleDebugAar' from ':runter-runtime:publishMavenPublicationToMavenRepository' using Task#mustRunAfter.
如何在我的gradle插件中动态地将参数传递给KAP编译器? val args = variant.javaCompileOptions.annotationProcessorOptions.arguments args["key"] = "value"
改为了(kotlin有效) val args = variant.javaCompilation.annotationProcessor.arguments args.put("root_project_dir", project.rootProject.projectDir.absolutePath)
改了(groovy 无效,估计配置的方式还是不对) project.extensions.findByName("android").applicationVariants.all { variant -> variant.javaCompileOptions.annotationProcessorOptions.arguments["root_project_dir"]= project.rootProject.projectDir.absolutePath }
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。