快速生成jboot/jfinal代码maven插件最佳配置

 

插件基本使用参考:http://www.javashuo.com/article/p-bpbvqzag-eq.htmlmysql

但有时候想经过命令行运行时覆盖默认的配置参数,若是是配置硬编码是不能覆盖的,仍是会使用pom.xml中配置的参数,举个栗子:sql

<plugin>
    <groupId>io.jcode</groupId>
    <artifactId>codegen</artifactId>
    <version>1.0-SNAPSHOT</version>
    <configuration>
        <dbType>mysql</dbType>
        <dbUrl>jdbc:mysql://127.0.0.1:3306/demo?useUnicode=true&amp;characterEncoding=utf-8</dbUrl>
        <dbUser>root</dbUser>
        <dbPassword>123456</dbPassword>
        <tablePrefix>test_</tablePrefix>
    </configuration>
</plugin>

想在运行时设置tablePrefix参数为user_,因而maven

mvn codegen:generate -DcodeType=MODEL -DtablePrefix=user_

可是运行发现最终生效的仍是pom中的test_ui

那这怎么才能经过命令行覆盖呢?有木有办法?编码

答案是确定的,看下面配置spa

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <tablePrefix>demo_</tablePrefix>
    <dbPassword>123456</dbPassword>
</properties>
....
<build>
    <finalName>${artifactId}-${version}</finalName>
    <plugins>
        <plugin>
            <groupId>io.jcode</groupId>
            <artifactId>codegen</artifactId>
            <version>1.0-SNAPSHOT</version>
            <configuration>
                <dbType>mysql</dbType>
                <dbUrl>jdbc:mysql://127.0.0.1:3306/demo?useUnicode=true&amp;characterEncoding=utf-8</dbUrl>
                <dbUser>root</dbUser>
                <dbPassword>${dbPassword}</dbPassword>
                <tablePrefix>${tablePrefix}</tablePrefix>
            </configuration>
        </plugin>
    </plugins>
</build>

再运行下命令就发现生效了.net

mvn codegen:generate -DcodeType=MODEL -DtablePrefix=user_

jcode maven plugin 的其余参数若是须要覆盖的以一样的方式配置,这样在运行时就能够很灵活很方便了。插件

注意:-DXXX的名称是properties配置对应的标签名称哦~,不是plugin的参数名称。命令行

最后总结下maven参数的传递优先级:code

mvn codegen:generate -DXXX=123

一、若是参数XXX不存在于pom.xml中,则XXX的值会以命令行设置的值写入,命令参数值行传递有效;

二、若是参数XXX存在于pom.xml中且是硬编码的形式配置的,其XXX的值将以pom中配置的写入,命令行参数值传递无效;

三、若是参数XXX存在于pom.xml中且是经过properties的形式${XXX}配置的,其XXX的值会以命令行设置的写入,命令行参数值传递有效。

相关文章
相关标签/搜索