[FLINK-8764] [quickstarts] Make quickstarts work out of the box for IDE and JAR packaging
- All Flink and Scala dependencies are properly set to provided
- That way, Maven JAR packaging behaves correctly by default
- Eclipse adds 'provided' dependencies to the classpath when running
programs, so works out of the box
- There is a profile that automatically activates in IntelliJ that adds the
necessary
dependencies in 'compile' scope to make it run out of the box.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/51262c89
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/51262c89
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/51262c89
Branch: refs/heads/master
Commit: 51262c89c7fad933ac267d606f7c85f46249d7f3
Parents: cb0ea0f
Author: Stephan Ewen <[email protected]>
Authored: Fri Feb 23 10:53:22 2018 +0100
Committer: Stephan Ewen <[email protected]>
Committed: Mon Feb 26 12:25:11 2018 +0100
----------------------------------------------------------------------
.../main/resources/archetype-resources/pom.xml | 230 ++++++++---------
.../main/resources/archetype-resources/pom.xml | 246 ++++++++-----------
2 files changed, 206 insertions(+), 270 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/51262c89/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git
a/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml
b/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml
index b78bf69..6ac05b0 100644
---
a/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml
+++
b/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/pom.xml
@@ -50,162 +50,53 @@ under the License.
</repository>
</repositories>
- <!--
-
- Execute "mvn clean package -Pbuild-jar"
- to build a jar file out of this project!
-
- How to use the Flink Quickstart pom:
-
- a) Adding new dependencies:
- You can add dependencies to the list below.
-
- b) Build a jar for running on the cluster:
-
- "mvn clean package -Pbuild-jar"
- This will create a fat-jar which contains all
dependencies necessary for running the created jar in a cluster.
- -->
-
<dependencies>
<!-- Apache Flink dependencies -->
- <dependency>
- <groupId>org.apache.flink</groupId>
- <artifactId>flink-core</artifactId>
- <version>${flink.version}</version>
- </dependency>
+ <!-- These dependencies are provided, because they should not
be packaged into the JAR file. -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
- <!-- This dependency is required to actually execute
jobs. It is currently pulled in by
- flink-streaming-java, but we explicitly depend
on it to safeguard against future changes. -->
<groupId>org.apache.flink</groupId>
-
<artifactId>flink-clients_${scala.binary.version}</artifactId>
+
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
+ <scope>provided</scope>
</dependency>
+
+ <!-- Add connector dependencies here. They must be in the
default scope (compile). -->
+
+ <!-- Example:
+
<dependency>
<groupId>org.apache.flink</groupId>
-
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
+
<artifactId>flink-connector-kafka-0.10_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
+ -->
- <!-- explicitly add a standard logging framework, as Flink does
not have
- a hard dependency on one specific framework by default
-->
+ <!-- Add logging framework, to produce console output when
running in the IDE. -->
+ <!-- These dependencies are excluded from the application JAR
by default. -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
+ <scope>runtime</scope>
</dependency>
</dependencies>
- <profiles>
- <profile>
- <!-- Profile for packaging correct JAR files -->
- <id>build-jar</id>
-
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.flink</groupId>
- <artifactId>flink-core</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.flink</groupId>
- <artifactId>flink-java</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.flink</groupId>
-
<artifactId>flink-clients_${scala.binary.version}</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.flink</groupId>
-
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>${log4j.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <!-- We use the maven-shade plugin to
create a fat jar that contains all dependencies
- except flink and its transitive
dependencies. The resulting fat-jar can be executed
- on a cluster. Change the value
of Program-Class if your program entry point changes. -->
- <plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-shade-plugin</artifactId>
- <version>3.0.0</version>
- <executions>
- <!-- Run shade goal on
package phase -->
- <execution>
-
<phase>package</phase>
- <goals>
-
<goal>shade</goal>
- </goals>
- <configuration>
-
<artifactSet>
-
<excludes>
-
<exclude>org.apache.flink:force-shading</exclude>
-
<exclude>com.google.code.findbugs:jsr305</exclude>
-
<exclude>org.slf4j:*</exclude>
-
</excludes>
-
</artifactSet>
-
<filters>
-
<filter>
-
<!-- Do not copy the signatures in the META-INF folder.
- Otherwise, this might cause
SecurityExceptions when using the JAR. -->
-
<artifact>*:*</artifact>
-
<excludes>
-
<exclude>META-INF/*.SF</exclude>
-
<exclude>META-INF/*.DSA</exclude>
-
<exclude>META-INF/*.RSA</exclude>
-
</excludes>
-
</filter>
-
</filters>
-
<transformers>
-
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-
<mainClass>${package}.StreamingJob</mainClass>
-
</transformer>
-
</transformers>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
<build>
<plugins>
+ <!-- Java Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@@ -215,12 +106,57 @@ under the License.
<target>1.8</target>
</configuration>
</plugin>
+
+ <!-- We use the maven-shade plugin to create a fat jar
that contains all necessary dependencies. -->
+ <!-- Change the value of <mainClass>...</mainClass> if
your program entry point changes. -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>3.0.0</version>
+ <executions>
+ <!-- Run shade goal on package phase -->
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <artifactSet>
+ <excludes>
+
<exclude>org.apache.flink:force-shading</exclude>
+
<exclude>com.google.code.findbugs:jsr305</exclude>
+
<exclude>org.slf4j:*</exclude>
+
<exclude>log4j:*</exclude>
+ </excludes>
+ </artifactSet>
+ <filters>
+ <filter>
+ <!-- Do
not copy the signatures in the META-INF folder.
+
Otherwise, this might cause SecurityExceptions when using the JAR. -->
+
<artifact>*:*</artifact>
+
<excludes>
+
<exclude>META-INF/*.SF</exclude>
+
<exclude>META-INF/*.DSA</exclude>
+
<exclude>META-INF/*.RSA</exclude>
+
</excludes>
+ </filter>
+ </filters>
+ <transformers>
+ <transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+
<mainClass>${package}.StreamingJob</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
- <!-- If you want to use Java 8 Lambda Expressions uncomment the
following lines -->
- <!--
<pluginManagement>
<plugins>
+
+ <!-- If you want to use Java 8 Lambda
Expressions uncomment the following lines -->
+ <!--
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
@@ -236,7 +172,9 @@ under the License.
</dependency>
</dependencies>
</plugin>
+ -->
+ <!-- This improves the out-of-the-box
experience in Eclipse by resolving some warnings. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
@@ -247,10 +185,10 @@ under the License.
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-assembly-plugin</artifactId>
-
<versionRange>[2.4,)</versionRange>
+
<artifactId>maven-shade-plugin</artifactId>
+
<versionRange>[3.0.0,)</versionRange>
<goals>
-
<goal>single</goal>
+
<goal>shade</goal>
</goals>
</pluginExecutionFilter>
<action>
@@ -277,6 +215,36 @@ under the License.
</plugin>
</plugins>
</pluginManagement>
- -->
</build>
+
+ <!-- This profile helps to make things run out of the box in IntelliJ
-->
+ <!-- Its adds Flink's core classes to the runtime class path. -->
+ <!-- Otherwise they are missing in IntelliJ, because the dependency is
'provided' -->
+ <profiles>
+ <profile>
+ <id>add-dependencies-for-IDEA</id>
+
+ <activation>
+ <property>
+ <name>idea.version</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-java</artifactId>
+ <version>${flink.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
+ <version>${flink.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
</project>
http://git-wip-us.apache.org/repos/asf/flink/blob/51262c89/flink-quickstart/flink-quickstart-scala/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git
a/flink-quickstart/flink-quickstart-scala/src/main/resources/archetype-resources/pom.xml
b/flink-quickstart/flink-quickstart-scala/src/main/resources/archetype-resources/pom.xml
index 2af7118..5828d73 100644
---
a/flink-quickstart/flink-quickstart-scala/src/main/resources/archetype-resources/pom.xml
+++
b/flink-quickstart/flink-quickstart-scala/src/main/resources/archetype-resources/pom.xml
@@ -52,171 +52,104 @@ under the License.
<scala.version>2.11.12</scala.version>
</properties>
- <!--
-
- Execute "mvn clean package -Pbuild-jar"
- to build a jar file out of this project!
-
- How to use the Flink Quickstart pom:
-
- a) Adding new dependencies:
- You can add dependencies to the list below.
-
- b) Build a jar for running on the cluster:
-
- "mvn clean package -Pbuild-jar"
- This will create a fat-jar which contains all
dependencies necessary for running the created jar in a cluster.
- -->
-
<dependencies>
<!-- Apache Flink dependencies -->
- <dependency>
- <groupId>org.apache.flink</groupId>
- <artifactId>flink-core</artifactId>
- <version>${flink.version}</version>
- </dependency>
- <dependency>
- <!-- This dependency is required to actually execute
jobs. It is currently pulled in by
- flink-streaming-java, but we explicitly depend
on it to safeguard against future changes. -->
- <groupId>org.apache.flink</groupId>
-
<artifactId>flink-clients_${scala.binary.version}</artifactId>
- <version>${flink.version}</version>
- </dependency>
+ <!-- These dependencies are provided, because they should not
be packaged into the JAR file. -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
+ <scope>provided</scope>
</dependency>
+ <!-- Scala Library, provided by Flink as well. -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Add connector dependencies here. They must be in the
default scope (compile). -->
+
+ <!-- Example:
+
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+
<artifactId>flink-connector-kafka-0.10_${scala.binary.version}</artifactId>
+ <version>${flink.version}</version>
</dependency>
+ -->
- <!-- explicitly add a standard logging framework, as Flink does
not have
- a hard dependency on one specific framework by default
-->
+ <!-- Add logging framework, to produce console output when
running in the IDE. -->
+ <!-- These dependencies are excluded from the application JAR
by default. -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
+ <scope>runtime</scope>
</dependency>
</dependencies>
- <profiles>
- <profile>
- <!-- Profile for packaging correct JAR files -->
- <id>build-jar</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <dependencies>
- <dependency>
- <groupId>org.apache.flink</groupId>
- <artifactId>flink-core</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.flink</groupId>
-
<artifactId>flink-clients_${scala.binary.version}</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.flink</groupId>
-
<artifactId>flink-scala_${scala.binary.version}</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.flink</groupId>
-
<artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
- <version>${flink.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.scala-lang</groupId>
- <artifactId>scala-library</artifactId>
- <version>${scala.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>${log4j.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <!-- We use the maven-shade plugin to
create a fat jar that contains all dependencies
- except flink and its transitive
dependencies. The resulting fat-jar can be executed
- on a cluster. Change the value
of Program-Class if your program entry point changes. -->
- <plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-shade-plugin</artifactId>
- <version>3.0.0</version>
- <executions>
- <!-- Run shade goal on
package phase -->
- <execution>
-
<phase>package</phase>
- <goals>
-
<goal>shade</goal>
- </goals>
- <configuration>
-
<artifactSet>
-
<excludes>
-
<exclude>org.apache.flink:force-shading</exclude>
-
<exclude>com.google.code.findbugs:jsr305</exclude>
-
<exclude>org.slf4j:*</exclude>
-
</excludes>
-
</artifactSet>
-
<filters>
-
<filter>
-
<!-- Do not copy the signatures in the META-INF folder.
-
Otherwise, this might cause SecurityExceptions when using the JAR. -->
-
<artifact>*:*</artifact>
-
<excludes>
-
<exclude>META-INF/*.SF</exclude>
-
<exclude>META-INF/*.DSA</exclude>
-
<exclude>META-INF/*.RSA</exclude>
-
</excludes>
-
</filter>
-
</filters>
-
<transformers>
-
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-
<mainClass>${package}.StreamingJob</mainClass>
-
</transformer>
-
</transformers>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
<build>
<plugins>
+ <!-- We use the maven-shade plugin to create a fat jar
that contains all necessary dependencies. -->
+ <!-- Change the value of <mainClass>...</mainClass> if
your program entry point changes. -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>3.0.0</version>
+ <executions>
+ <!-- Run shade goal on package phase -->
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <artifactSet>
+ <excludes>
+
<exclude>org.apache.flink:force-shading</exclude>
+
<exclude>com.google.code.findbugs:jsr305</exclude>
+
<exclude>org.slf4j:*</exclude>
+
<exclude>log4j:*</exclude>
+ </excludes>
+ </artifactSet>
+ <filters>
+ <filter>
+ <!-- Do
not copy the signatures in the META-INF folder.
+
Otherwise, this might cause SecurityExceptions when using the JAR. -->
+
<artifact>*:*</artifact>
+
<excludes>
+
<exclude>META-INF/*.SF</exclude>
+
<exclude>META-INF/*.DSA</exclude>
+
<exclude>META-INF/*.RSA</exclude>
+
</excludes>
+ </filter>
+ </filters>
+ <transformers>
+ <transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+
<mainClass>${package}.StreamingJob</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Java Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@@ -226,6 +159,8 @@ under the License.
<target>1.8</target>
</configuration>
</plugin>
+
+ <!-- Scala Compiler -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
@@ -240,7 +175,7 @@ under the License.
</executions>
</plugin>
- <!-- Eclipse Integration -->
+ <!-- Eclipse Scala Integration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
@@ -255,10 +190,8 @@ under the License.
<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<classpathContainers>
-
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER
- </classpathContainer>
-
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER
- </classpathContainer>
+
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer>
+
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<exclude>org.scala-lang:scala-library</exclude>
@@ -270,8 +203,6 @@ under the License.
</sourceIncludes>
</configuration>
</plugin>
-
- <!-- Adding scala source directories to build path -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
@@ -307,4 +238,41 @@ under the License.
</plugin>
</plugins>
</build>
+
+ <!-- This profile helps to make things run out of the box in IntelliJ
-->
+ <!-- Its adds Flink's core classes to the runtime class path. -->
+ <!-- Otherwise they are missing in IntelliJ, because the dependency is
'provided' -->
+ <profiles>
+ <profile>
+ <id>add-dependencies-for-IDEA</id>
+
+ <activation>
+ <property>
+ <name>idea.version</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+
<artifactId>flink-scala_${scala.binary.version}</artifactId>
+ <version>${flink.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+
<artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
+ <version>${flink.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>${scala.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
</project>
