# ClassPlaceholder **Repository Path**: seek_admin/ClassPlaceholder ## Basic Information - **Project Name**: ClassPlaceholder - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-03 - **Last Updated**: 2022-01-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ClassPlaceholder 动态替换jar包及java源代码中的值。在jar包或java文件以占位符的形式定义常量。在引入jar包时动态替换 原字符串。在java源文件中同样以占位符的形式定义常量。在generateBuildConfig 任务后会自动修改指定的值。 ## 使用 1. 引入仓库: ``` allprojects { repositories { ... maven { url 'https://plugins.gradle.org/m2/' } } } ``` 2. 引入插件: ``` dependencies { classpath 'com.android.tools.build:gradle:3.1.4' classpath 'gradle.plugin.me.xp.gradle:placeholder:1.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } ``` 3. 要替换的代码中使用占位符定义要替换的值,如: ``` public static final String TEST_PUBLIC = "${public}"; private static final String TEST_PRIVATE = "${private}"; ``` 4. 在主项目的build.gradle文件中添加`placeholder`插件,定义在替换的值及文件名,如: ``` apply plugin: 'me.xp.gradle.placeholder.PlaceholderPlugin' placeholders { addholder { //is modify source java file isModifyJava = true //modify file name classFile = "me/xp/gradle/classplaceholder/AppConfig.java" //replace name and value values = ['public' : 'AppConfigPubic', 'private': 'AppConfigPrivate', 'field' : 'AppConfigField'] } addholder { isModifyJava = false classFile = "me/xp/gradle/jarlibrary/JarConfig.class" values = ['config': 'JarConfigPubic'] } } ``` 5. 若修改替换值,需要先执行`clean`命令,再build。