alibaba / testable-mock

换种思路写Mock,让单元测试更简单
https://alibaba.github.io/testable-mock/
MIT License
1.82k stars 309 forks source link

testable-mock依赖了tools.jar,删除是否有影响 #265

Open ymlsmile opened 2 years ago

ymlsmile commented 2 years ago

maven项目引入testable-mock后发现在copy-dependencies的时候会将tools.jar打包,请问下使用如下方式去掉是否有影响?

    <dependency>
        <groupId>com.alibaba.testable</groupId>
        <artifactId>testable-all</artifactId>
        <version>${testable.version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <artifactId>tools</artifactId>
                <groupId>sun.jdk</groupId>
            </exclusion>
        </exclusions>
    </dependency>
linfan commented 2 years ago

Testable只有@EnablePrivateAccess注解依赖了sun.jdk包,只要没有用到这个注解,就可以安全移除。

同时由于引入testable-all时候是指定了<scope>test</scope>的,在打工程jar包的时候也不会将testable-all和依赖打到产物里。

ymlsmile commented 2 years ago

Testable只有@EnablePrivateAccess注解依赖了sun.jdk包,只要没有用到这个注解,就可以安全移除。

同时由于引入testable-all时候是指定了<scope>test</scope>的,在打工程jar包的时候也不会将testable-all和依赖打到产物里。

好的,使用过程中发现使用maven-dependency-plugin插件的时候会将sun.jdk包引入进来

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${assemblyDirectory}/${serviceId}/lib/</outputDirectory>
                <stripVersion>true</stripVersion>
                                <includeScope>compile</includeScope>
            </configuration>
        </execution>
    </executions>
</plugin>