问题:
在Flink scala中使用WatermarkStrategy类中的方法maven编译时抛出以下异常
[ERROR] /Users/duzhixin/flink-dw/src/main/scala/come/bigdata/etl/FlinkEvent.scala:26: error: Static methods in interface require -target:jvm-1.8
[INFO] val eventStream = env.fromSource(kafkaSource, WatermarkStrategy.noWatermarks[String],"Kafka Source With Custom Watermark Strategy")
解决:
maven里加上
<configuration>
<args>
<arg>-target:jvm-1.8</arg>
</args>
</configuration>
如下
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<configuration>
<args>
<arg>-target:jvm-1.8</arg>
</args>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
完整scala maven build pom.xml如下,net.alchim31.maven 里的scala maven 插件用了会有坑,注释掉了
<build>
<!-- <sourceDirectory>src/main/scala</sourceDirectory>-->
<finalName>flink-dw</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<configuration>
<args>
<arg>-target:jvm-1.8</arg>
</args>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!--manven打包插件-->
<!-- 用于打可执行jar包 -->
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>target/classes/</classesDirectory>
<archive>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<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>
<type>jar</type>
<includeTypes>jar</includeTypes>
<!--<useUniqueVersions>false</useUniqueVersions> -->
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>net.alchim31.maven</groupId>-->
<!-- <artifactId>scala-maven-plugin</artifactId>-->
<!-- <version>4.5.6</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>scala-compile-first</id>-->
<!-- <phase>process-resources</phase>-->
<!-- <goals>-->
<!-- <goal>compile</goal>-->
<!-- <goal>testCompile</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- <configuration>-->
<!-- <jvmArgs>-->
<!-- <jvmArg>-Xms64m</jvmArg>-->
<!-- <jvmArg>-Xmx1024m</jvmArg>-->
<!-- </jvmArgs>-->
<!-- <args>-->
<!-- <arg>-nobootcp</arg>-->
<!-- </args>-->
<!-- <addScalacArgs>-target:jvm-1.8</addScalacArgs>-->
<!-- <jvmArgs>1.8</jvmArgs>-->
<!-- </configuration>-->
<!-- </plugin>-->
</plugins>
</build>
但是如果要在idea里run,还需要单独设置 scala compiler