Skip to content

Commit

Permalink
add: Support for dynamically configuring configFile through the `gr…
Browse files Browse the repository at this point in the history
…adle` command line.
  • Loading branch information
shalousun committed Mar 24, 2024
1 parent cdf2251 commit b209d3a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
20 changes: 20 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`中。

```
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ly/doc/gradle/constant/GlobalConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,6 @@ public interface GlobalConstants {
*/
String SRC_MAIN_JAVA_PATH = "src/main/java";

String CONFIG_FILE = "smartdoc.configFile";

}
25 changes: 13 additions & 12 deletions src/main/java/com/ly/doc/gradle/task/DocBaseTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -99,7 +94,13 @@ public void action() {
Set<String> 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);
}
Expand Down Expand Up @@ -130,7 +131,7 @@ public void action() {
/**
* Classloading
*
* @return JavaProjectBuilder
* @return JavaProjectBuilder
*/
private JavaProjectBuilder buildJavaProjectBuilder(Project project, Set<String> excludes, Set<String> includes) {
SortedClassLibraryBuilder classLibraryBuilder = new SortedClassLibraryBuilder();
Expand All @@ -146,10 +147,10 @@ private JavaProjectBuilder buildJavaProjectBuilder(Project project, Set<String>
}
}
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;
}
Expand Down

0 comments on commit b209d3a

Please sign in to comment.