Generate Database Documentation with Screw and Maven in Minutes
This guide shows how to use the open‑source Screw tool together with Maven to automatically generate HTML, DOC, or MD documentation for MySQL, MariaDB, TiDB, Oracle, SQL Server, PostgreSQL and other databases, including configuration, code examples, and output options.
Background
Our department needed a unified order platform and had to document hundreds of tables across multiple business lines. Manually handling each table was tedious, so we searched GitHub for a tool and discovered
screw, which can generate database documentation automatically.
Supported Databases
MySQL
MariaDB
TiDB
Oracle
SqlServer
PostgreSQL
Cache DB
Configuration
1. pom.xml dependencies
<code><!-- screw core -->
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.3</version>
</dependency>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!-- mysql driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency></code>2. Data source configuration
<code>spring.datasource.url=jdbc:mysql://45.93.1.5:3306/fire?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.xa.properties.useInformationSchema=true</code>3. Screw core configuration (pom or code)
The
screwplugin can be configured in the Maven
pom.xmlor invoked programmatically. Below is a Maven plugin example:
<code><build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-maven-plugin</artifactId>
<version>1.0.3</version>
<dependencies>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!-- mysql driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</dependencies>
<configuration>
<username>root</username>
<password>123456</password>
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<jdbcUrl>jdbc:mysql://41.92.6.5:3306/fire</jdbcUrl>
<fileType>HTML</fileType>
<openOutputDir>false</openOutputDir>
<produceType>freemarker</produceType>
<description>数据库文档生成</description>
<version>${project.version}</version>
<title>fire数据库文档</title>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build></code>After configuration, run the Maven goal
screwto generate the documentation.
4. Programmatic generation (SpringBootTest example)
<code>@SpringBootTest
public class ScrewApplicationTests {
@Autowired
ApplicationContext applicationContext;
@Test
void contextLoads() {
DataSource dataSourceMysql = applicationContext.getBean(DataSource.class);
// Engine configuration
EngineConfig engineConfig = EngineConfig.builder()
.fileOutputDir("D:/")
.openOutputDir(false)
.fileType(EngineFileType.HTML)
.produceType(EngineTemplateType.freemarker)
.build();
// Documentation configuration
Configuration config = Configuration.builder()
.version("1.0.3")
.description("生成文档信息描述")
.dataSource(dataSourceMysql)
.engineConfig(engineConfig)
.produceConfig(getProcessConfig())
.build();
new DocumentationExecute(config).execute();
}
/**
* Configure tables to include or ignore.
*/
public static ProcessConfig getProcessConfig() {
List<String> ignoreTableName = Arrays.asList("a", "test_group");
List<String> ignorePrefix = Arrays.asList("a", "t");
List<String> ignoreSuffix = Arrays.asList("_test", "czb_");
return ProcessConfig.builder()
.designatedTableName(Arrays.asList("fire_user"))
.designatedTablePrefix(new ArrayList<>())
.designatedTableSuffix(new ArrayList<>())
.ignoreTableName(ignoreTableName)
.ignoreTablePrefix(ignorePrefix)
.ignoreTableSuffix(ignoreSuffix)
.build();
}
}
</code>Document Formats
The
screwtool can output documentation in three formats:
HTML,
DOC, and
MD. Change the format by setting
fileTypein the configuration or in the pom.
<code>.fileType(EngineFileType.HTML)</code> <code><fileType>MD</fileType></code>DOC style
HTML style
MD style
Conclusion
The Screw tool proved extremely useful, allowing us to finish the documentation task quickly and efficiently.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.