diff --git a/README.md b/README.md index 97ffbcc..81e3830 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,25 @@ smartdoc { include 'org.springframework.boot:spring-boot-starter-tomcat' } ``` +For the configuration of `configFile`, you can also dynamically override it through the `gradle` command line. Before version `3.0.3`, you can add dynamic configuration to get the `configFile` in `build.gradle`, for example: +```groovy +smartdoc { + configFile = project.hasProperty('smartdoc.configFile') ? file(project.getProperty('smartdoc.configFile')) : file("src/main/resources/smart-doc.json") +} +``` +After configuring, you can directly override it through the command line: +```shell +gradle smartdoc -Psmartdoc.configFile=src/main/resources/smart-doc.json +``` +From version `3.0.3` onwards, the configuration of dynamically configuring `configFile` in `build.gradle` is very simple, and the plugin has the ability to completely override it. +```groovy +smartdoc { + configFile = file("src/main/resources/smart-doc.json") +} +``` +After configuration, you can directly use `-Psmartdoc.configFile` to override it. + + For multi-module gradle projects, if you do not want to configure in each module, you can put the `smart-doc` plugin related configuration into subprojects. ``` subprojects{ diff --git a/README_CN.md b/README_CN.md index 46c60ef..08e153c 100644 --- a/README_CN.md +++ b/README_CN.md @@ -62,6 +62,26 @@ smartdoc { include 'org.springframework.boot:spring-boot-starter-tomcat' } ``` +对于`configFile`的配置,你也可以通过`gradle`命令行来动态覆盖。在`3.0.3`之前, +可以在`build.gradle`中添加动态获取`configFile`的配置, 例如: +```groovy +smartdoc { + configFile = project.hasProperty('smartdoc.configFile') ? file(project.getProperty('smartdoc.configFile')) : file("src/main/resources/smart-doc.json") +} +``` +配置好后直接通过命令行覆盖: +```shell +gradle smartdoc -Psmartdoc.configFile=src/main/resources/smart-doc.json +``` +在`3.0.3`之后,`build.gradle`中配置动态配置`configFile`很简单,插件完全具备覆盖的功能。 +```groovy +smartdoc { + configFile = file("src/main/resources/smart-doc.json") +} +``` +配置后直接使用`-Psmartdoc.configFile`即可覆盖 + + 对于多模块的`Gradle`,把`smart-doc`插件相关配置放到根目录`build.gradle`的`subprojects`中。 ``` diff --git a/src/main/java/com/ly/doc/gradle/constant/GlobalConstants.java b/src/main/java/com/ly/doc/gradle/constant/GlobalConstants.java index ba2765b..8f1602b 100644 --- a/src/main/java/com/ly/doc/gradle/constant/GlobalConstants.java +++ b/src/main/java/com/ly/doc/gradle/constant/GlobalConstants.java @@ -121,4 +121,6 @@ public interface GlobalConstants { */ String SRC_MAIN_JAVA_PATH = "src/main/java"; + String CONFIG_FILE = "smartdoc.configFile"; + } diff --git a/src/main/java/com/ly/doc/gradle/task/DocBaseTask.java b/src/main/java/com/ly/doc/gradle/task/DocBaseTask.java index 2879890..5d0e41f 100644 --- a/src/main/java/com/ly/doc/gradle/task/DocBaseTask.java +++ b/src/main/java/com/ly/doc/gradle/task/DocBaseTask.java @@ -56,12 +56,7 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.TreeMap; +import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -99,7 +94,13 @@ public void action() { Set includes = pluginExtension.getInclude(); javaProjectBuilder = buildJavaProjectBuilder(project, excludes, includes); javaProjectBuilder.setEncoding(Charset.DEFAULT_CHARSET); - File file = pluginExtension.getConfigFile(); + File file; + // Also configurable with Gradle or System Property: ${smartdoc.configFile} + if (project.hasProperty(GlobalConstants.CONFIG_FILE)) { + file = new File((String) project.findProperty(GlobalConstants.CONFIG_FILE)); + } else { + file = pluginExtension.getConfigFile(); + } if (Objects.isNull(file)) { file = new File(GlobalConstants.DEFAULT_CONFIG); } @@ -130,7 +131,7 @@ public void action() { /** * Classloading * - * @return JavaProjectBuilder + * @return JavaProjectBuilder */ private JavaProjectBuilder buildJavaProjectBuilder(Project project, Set excludes, Set includes) { SortedClassLibraryBuilder classLibraryBuilder = new SortedClassLibraryBuilder(); @@ -146,10 +147,10 @@ private JavaProjectBuilder buildJavaProjectBuilder(Project project, Set } } SourceSetUtil.getDefaultMainJava(project) - .ifPresent(src -> { - getLogger().quiet(MSG + src); - javaDocBuilder.addSourceTree(src); - }); + .ifPresent(src -> { + getLogger().quiet(MSG + src); + javaDocBuilder.addSourceTree(src); + }); loadSourcesDependencies(javaDocBuilder, project, excludes, includes); return javaDocBuilder; }