maven 插件里面的版本依赖怎么传递

2020-06-30 10:49:47 +08:00
 Vimax

版本管理的 Pom 文件里面,加入平 flyway 插件和其依赖的 mysql 驱动。

版本号传递时,plugin 的版本号可以传递过去,但是 plugin 里面依赖的 dependency,即 Mysql 的版本号无法传递过去,使用 maven 命令就报错。已经刷新多次 maven 依赖了。

当指定子工程中 flyway 插件下的 mysql 驱动版本号时,错误就没有了。一删除版本号,错误又恢复了。

[ERROR]     'build.plugins.plugin[org.flywaydb:flyway-maven-plugin].dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing. @ line 78, column 33
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.6.RELEASE</version>
                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>${flyway.version}</version>
                <executions>
                    <!--当 install 时会执行 migrate-->
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>migrate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>${mysql.version}</version>
                    </dependency>
                </dependencies>

                <configuration>
                    <driver>com.mysql.jdbc.Driver</driver>
                    <url>jdbc:mysql://xxipxx:xxportxx/xxdb.schemaxx?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false</url>
                    <user>root</user>
                    <password>1234</password>
                    <!--<schemas></schemas>-->
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    </build

在子工程中,加入对应的

   <build>
        <plugins>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <executions>
                    <!--当 install 时会执行 migrate-->
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>migrate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                    </dependency>
                </dependencies>
                <configuration>
                    <driver>com.mysql.jdbc.Driver</driver>
                    <url>jdbc:mysql://xxipxx:xxportxx/xxdb.schemaxx?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false</url>
                    <user>root</user>
                    <password>1234</password>
                    <!--<schemas></schemas>-->
                </configuration>
            </plugin>
        </plugins>
    </build
1114 次点击
所在节点    Java
1 条回复
hantsy
2020-07-03 20:23:53 +08:00
父子关系 Plugin 依赖可能是个特例,Maven 目前应该是不传递的。另外父子同名的 Profile 好像也有类似的依赖问题。这个还是查一下文档比较好。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/685843

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX