fuzhengwei / itstack-demo-design

:art: 《重学Java设计模式》是一本互联网真实案例实践书籍。以落地解决方案为核心,从实际业务中抽离出,交易、营销、秒杀、中间件、源码等22个真实场景,来学习设计模式的运用。欢迎关注小傅哥,微信(fustack),公众号:bugstack虫洞栈,博客:https://bugstack.cn
https://bugstack.cn
Apache License 2.0
6.42k stars 1.91k forks source link

在编译过程中遇到的一些问题 #26

Open xkl700 opened 3 years ago

xkl700 commented 3 years ago

环境 JDK1.8.0251+MAVEN3.6.1+IDEA

[1]itstack-demo-design-8-02 报错信息为 错误: -source 1.6 中不支持 diamond 运算符

修改子项目下的pom.xml

  <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>8</source>
                  <target>8</target>
              </configuration>
          </plugin>
      </plugins>
  </build> 

[2]itstack-demo-design-10-01 报错信息为 Cannot resolve org.itstack.demo.design.domain.UserInfo

我发现他打包的时候将itstack-demo-design-10-00项目的包打到了org.springframework.boot下 修改itstack-demo-design-10-00子项目下的pom.xml

    <!--修改前-->
    <packaging>war</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <!--修改后-->
   <parent>
        <artifactId>itstack-demo-design</artifactId>
        <groupId>org.itstack</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <packaging>jar</packaging>

另<dependencies></dependencies><groupId></groupId>的值为org.springframework.boot的都加上<version>2.1.2.RELEASE</version>

[3]报错信息为 错误: -source 1.5 中不支持 diamond 运算符

Maven Compiler 插件默认会加 -source 1.5 及 -target 1.5 参数来编译(估计是为了兼容一些比较老的 Linux 服务器操作系统,它们通常只有 JDK 5),而我们的代码里使用了 JDK 7/8 的语法。

    <build>
        ...
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
        ...
    </build>
orangle commented 3 years ago

老哥 提个pr呀 我又躺了一遍