Hello Gradle. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

Similar documents
Hello Maven. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

This tutorial explains how you can use Gradle as a build automation tool for Java as well as Groovy projects.

The Workshop. Slides (you have a copy in the zip) Practical labs Ask questions

Chapter 1. Installation and Setup

Gradle. The Basics and Beyond

Software Engineering - Development Infrastructure 2. Kristjan Talvar Nortal

Getting Started with Gradle

JVM Survival Guide. Hadi Hariri

... Fisheye Crucible Bamboo

Class Dependency Analyzer CDA Developer Guide

Lab 5 Exercise Build and continuous integration tools

Enter the Gradle Hans Dockter CEO, Gradleware Founder Gradle

Maven Introduction to Concepts: POM, Dependencies, Plugins, Phases

What s NetBeans? Like Eclipse:

The jpos REST tutorial shows you how to use an out-of-the-box binary distribution of jpos to build a REST server that responds to an /echo call.

GAVIN KING RED HAT CEYLON SWARM

JavaBasel 16. René Gröschke. Gradle 3.0 and beyond. Gradle 3.0 and beyond - #javabasel

Getting Started with Java. Atul Prakash

Selenium Testing Course Content

JBoss Tattletale. Betraying all your project's naughty little secrets

Package Management and Build Tools

Groovy. Extending Java with scripting capabilities. Last updated: 10 July 2017

Tattletale. What is Tattletale? Enterprise archives JBoss Application Server 7 Putting it all together Roadmap

COMP220/285 Lab sessions 1-3

IBM. IBM WebSphere Application Server Migration Toolkit. WebSphere Application Server. Version 9.0 Release

IntelliJ IDEA, the most intelligent Java IDE

Build Automation Kurt Christensen

Gradle Leveraging Groovy for Building Java Applications. Hans Dockter Gradle Project Lead

C++ Binary Dependency Management with Gradle. Hugh Greene

Getting Started with Eclipse for Java

Javac and Eclipse tutorial

CHAPTER 6. Java Project Configuration

Maven POM project modelversion groupid artifactid packaging version name

Red Hat JBoss Enterprise Application Platform 6.4

About me. Jesper Pedersen. Project lead for. Chairman for Boston JBoss User Group. Core developer, JBoss by Red Hat

APEX Developer Guide. Sven van der Meer, Liam Fallon, John Keeney. Version SNAPSHOT, T11:44:57Z

Getting Started with Eclipse for Java

gradle : Building Android Apps Mobel Meetup

ewon Flexy JAVA J2SE Toolkit User Guide

Using Eclipse Europa - A Tutorial

Setup and Getting Startedt Customized Java EE Training:

For live Java EE training, please see training courses at

Topics covered. Introduction to Maven Maven for Dependency Management Maven Lifecycles and Plugins Hands on session. Maven 2

Exceptions and Libraries

Hello World. Lesson 1. Create your first Android. Android Developer Fundamentals. Android Developer Fundamentals

I Got My Mojo Workin'

Starting In Java With JPT in Eclipse

IntelliJ IDEA Getting Started Guide for FIRST Robotics Competition

Fat / Uber jars - Using the Shade Plugin

Repository Management and Sonatype Nexus. Repository Management and Sonatype Nexus

Installation Guide for the TITAN Designer and TITAN Executor for the Eclipse IDE

FIWARE Advanced Middleware KIARA Documentation

AUTOMATION TESTING FRAMEWORK FOR LUMINOUS LMS

JBoss Enterprise Application Platform 6.2

vsphere Client SDK Developer Guide 03 MAY 2018 VMware vsphere vsphere Client SDK

Red Hat Developer Tools

JDO Tools Guide (v5.1)

Unit Testing. CS 240 Advanced Programming Concepts

Oracle Code Day Hands On Labs (HOL) (Install, Repository, Local Deploy, DevCS, OACCS)

1. Go to the URL Click on JDK download option

Module Road Map. 7. Version Control with Subversion Introduction Terminology

16.410: Jump Starting With Java

Why switch exist-db from Ant to Maven?

Java Programming. Manuel Oriol, March 22nd, 2007

POOSL IDE Installation Manual

Red Hat Developer Tools

Tutorial: Developing a Simple Hello World Portlet

CHAPTER 6. Organizing Your Development Project. All right, guys! It s time to clean up this town!

Software Installation Guide

Apache Buildr in Action

JBoss Tattletale 1.1 Developer's Guide

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

SpringSource Tool Suite 2.7.1

Tutorial on OpenCV for Android Setup

CPSC 324 Topics in Java Programming

UNic Eclipse Mini Tutorial (Updated 06/09/2012) Prepared by Harald Gjermundrod

Maven. INF5750/ Lecture 2 (Part II)

WA2621 DevOps Foundations for Java with Git, Jenkins, and Maven. Classroom Setup Guide. Web Age Solutions Inc. Web Age Solutions Inc.

COMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE. Instructor: Prasun Dewan (FB 150,

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

JBoss SOAP Web Services User Guide. Version: M5

Simplified Build Management with Maven

Software Development Kit for ios and Android

1. The Apache Derby database

Index. Bitwise operations, 131. Cloud, 88, 101

vsphere Client SDK Developer Guide 17 APR 2018 VMware vsphere 6.7 vsphere Client SDK 6.7

Red Hat JBoss Developer Studio 11.3

Red Hat JBoss Enterprise Application Platform 7.2

MAVEN INTERVIEW QUESTIONS

Hello Java Enterprise Edition

Software Installation for CS121

XML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.

Contents. Enterprise Systems Maven and Log4j. Maven. What is maven?

DITA Gradle and Git. DITA-OT day Rotterdam

This assignment requires that you complete the following tasks (in no particular order).

Last Updated: FRC 2019 BETA

Component based Development. Table of Contents. Notes. Notes. Notes. Web Application Development. Zsolt Tóth

Software Development. COMP220/COMP285 Seb Coope Ant: Structured Build

S8352: Java From the Very Beginning Part I - Exercises

Lab Android Development Environment

Transcription:

Hello Gradle TestNG, Eclipse, IntelliJ IDEA Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2 Dávid Bedők 2017.09.18. v0.2 Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 1 / 27

Java project structure How to organize our source codes? Java Build tools: batch files / bash scripts javac Apache ANT (+ Apache IVY) IDE (Eclipse, IntellJ IDEA,...) Apache Maven build tool Gradle What kinds of things should be considered? There will be unit tests? separate source folder for the unit tests (test and main) There will be resources? separate source folder for the resources (resources) There will be non-java source codes too? separate source folders for the disparate sources (java, scala, groovy, etc.) Java philosophy transparency, clarity classpath (cp) usage SAR*: JBoss specific APK**: android specific usage of JAR, WAR, EAR, SAR*, APK** packagings Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 2 / 27

Java project structure javac We can do almost everything with that (there are no rules)! We add all the source folders to the javac program via CLI. Directory structure bin/ src1/ source folder src2/ source folder The Application class uses an instance of ImperialToMetricCalculator class. Both classes are compiled into the same package, so application doesn t import the calculator class (at runtime both classes will be at the same place). \hellotest 1 > javac -d./ bin./ src1 /hu/ qwaevisz / demo / Application. java./ src2 / hu/ qwaevisz / demo / ImperialToMetricCalculator. java 2 > java - cp./ bin hu. qwaevisz. demo. Application Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 3 / 27

Java project structure Eclipse IDE Configuration of the Eclipse s default Java project : Directory structure bin/ src/ source folder Eclipse s Java project with unit tests: Directory structure bin/ src/ main/ source folder test/ source folder In most of the IDEs these rules can be configure completely (Eclipse: Project properties Java Build Path Source tab). Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 4 / 27

Java project structure Gradle Default configuration of the Gradle s java plugin: Directory structure bin/ src/ main/ java/ source folder resources/ source folder test/ java/ source folder resources/ source folder Of course you are able to change these settings in Gradle. But if we use this default configuration we will have a very simple, clean and small build script to start the work. Note : All the source folders and the resources directories are part of the classpath (we can reach its content during runtime). Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 5 / 27

JAR - Java ARchive ZIP format which keeps (Java) byte codes (*.class), configuration files (e.g.: *.properties, *.xml, etc.) and a special metafile which contains key-value pairs (MANIFEST.MF). Directory structure META INF/ MANIFEST.MF hu/ qwaevisz/ demo/ HelloWorld.class Lorem.class log4j.xml It s structure is predefined, there is an option to store source files (e.g.: *.java, *.groovy, etc.) at the same place where the byte codes are located. 1 Manifest - Version : 1.0 2 Created - By: 1.7.0 _67 ( Oracle Corporation ) MANIFEST.MF Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 6 / 27

Executable JAR file The Main-Class key has to be part of the MANIFEST.MF file, and the value of this key is the full qualified name of the entry point of the application. 1 Manifest - Version : 1.0 2 Created - By: 1.7.0 _67 ( Oracle Corporation ) 3 Main - Class : hu. qwaevisz. demo. Application MANIFEST.MF 1 > cd bin 2 > jar cvfe calculator. jar hu. qwaevisz. demo. Application hu/ qwaevisz / demo / Application. class hu/ qwaevisz / demo / ImperialToMetricCalculator. class 3 > cd.. 4 > java - jar bin / calculator. jar create new archive verbose specify archive file name (2) sepcify entry point (main class) (3) Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 7 / 27

Eclipse OXYGEN IDE, 2017 June Eclipse IDE for Java EE Developers Download: https://www.eclipse.org/downloads/ Version: 4.7.0 Install: unzip or installer Integrated plugins: Gradle Maven Git EclEmma Java Code Coverage... Additional plugins (Help / Eclipse Marketplace): TestNG (filter: testng) http://beust.com/eclipse In case of Hungarian keyboard layout (and usage) you have to turn off some shortcut keys (e.g. "{" (Ctrl + B): Preferences General Keys Skip all brakepoints (Ctrl + Alt + B) Unbind Basic usage of Eclipse IDE: http://users.nik.uni obuda.hu/bedok.david/jse.html Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 8 / 27

Eclipse configuration Code Style Formatter Window Preferences (type: formatter) Java Code Style Formatter New... / Import...: uni-obuda-java-formatter Initialize: Eclipse [build-in] Indentation Indent Statement within switch body Line Wrapping General Maximum line width: 160 Line Wrapping Enum declaration Policy: Wrap all elements, every element on a new line Constants policy: Wrap all elements, every element on a new line + Force split Comments Line width Maximum: 120 \eclipse\uni obuda java formatter.xml Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 9 / 27

Eclipse configuration Save Actions Window Preferences (type: save actions) Java Editor Save Actions Perform the selected actions on save Format source code (all lines) Organize imports Additional actions - Configure Code Organaizing: Remove trailing whitespaces Code Style: Use blocks in if/while/for/do statements Member Accesses: Use this qualifier for field accesses: Always Member Accesses: Use this qualifier for method accesses: Always Unnecessary Code: Remove unused imports Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 10 / 27

IntelliJ IDEA IDE Download: https://www.jetbrains.com/idea/ Commercial product The community version doesn t support the JavaEE, but without this feature it is usable for professional work as well (event JavaEE projects). Sometimes it is faster than Eclipse Different shortcut keys, hard to get used to Integrated Maven/Gradle/Git plugins Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 11 / 27

Hello World src main java hu qwaevisz hello Application.java 1 package hu. qwaevisz. hello ; 2 3 public class Application { 4 5 public static void main ( final String [] args ) { 6 System. out. println (" Hello World "); 7 } 8 9 public int add ( final int a, final int b) { 10 return a + b; 11 } 12 13 } Application.java [gradle maven]\helloworld Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 12 / 27

TestNG 3 rd party library http://testng.org/ GitHub: https://github.com/cbeust/testng Version: 6.11 Artifactory URL: org.testng:testng:6.11 group/groupid: org.testng name/artifactid: testng version: 6.11 Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 13 / 27

Unit Test with TestNG src test java hu qwaevisz hello ApplicationTest.java 1 package hu. qwaevisz. hello ; 2 3 import org. testng. Assert ; 4 import org. testng. annotations. Test ; 5 6 public class ApplicationTest { 7 8 @Test 9 public void addnumbers () { 10 Application app = new Application (); 11 Assert. assertequals ( app. add (2, 3), 5); 12 } 13 14 } ApplicationTest.java Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 14 / 27

Gradle Build tool https://gradle.org/ Download: https://gradle.org/releases/ Version: 4.1 supports Java, C++, Python and more programming languages supports monorepo and multi-repo as well multi-language, multi-platform, multi-project and multi-channel software development (SaaS: Software as a Service) Install: unzip Environment variables: GRADLE_HOME c:\apps\gradle 2.6 Path modification %Path%;%GRADLE_HOME%\bin Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 15 / 27

Gradle major properties Apache Ant based build system http://ant.apache.org/ Apache Ivy styled dependency management http://ant.apache.org/ivy/ intelligent default environments like Apache Maven https://maven.apache.org/ speed and hashing of Git metaprogramming with Apache Groovy / JetBrains Kotlin http://groovy lang.org/ https://kotlinlang.org/ Directed Acyclic Graph (DAG) Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 16 / 27

Gradle 1 > gradle -- version 2 3 ------------------------------------------------------------ 4 Gradle 4.1 5 ------------------------------------------------------------ 6 7 Build time : 2017-08 -07 14:38:48 UTC 8 Revision : 941559 e020f6c357ebb08d5c67acdb858a3defc2 9 10 Groovy : 2.4.11 11 Ant : Apache Ant ( TM) version 1.9.6 compiled on June 29 2015 12 JVM : 1.8.0 _101 ( Oracle Corporation 25.101 - b13 ) 13 OS: Mac OS X 10.12.6 x86_64 Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 17 / 27

Gradle - Eclipse integration Gradle s eclipse plugin constructs all the required configuration files and with these files you can import your project into Eclipse with ease. Eclipse s Gradle plugin recognizes the gradle s build files and Eclipse can handle the project properly. In the past it was recommended to use both ways at the same time, but now the official Eclipse plugin (buildship) is good enough. Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 18 / 27

Hello Gradle! Hello World application with Gradle [gradle maven]\helloworld 1 apply plugin : java 1 > gradle clean build 2 3 > Configure project : 4 Task name : info 5 Project name : helloworld 6 7 8 BUILD SUCCESSFUL in 1s 9 5 actionable tasks : 5 executed build.gradle output: build\libs\helloworld.jar (non-executable) clean, build tasks of java plugin dependent tasks of build: compilejava, jar, assemble, test, check,... Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 19 / 27

Create a custom Gradle task 1 apply plugin : java 2 3 sourcecompatibility = 1.7 4 version = 1.0 5 6 task info () { 7 println " Task name : " + name 8 println " Project name : " + project. name 9 println " Project version : " + version 10 } build.gradle 1 > gradle info 2 3 > Configure project : 4 Task name : info 5 Project name : helloworld 6 Project version : 1.0 7 8 9 BUILD SUCCESSFUL in 0s Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 20 / 27

Executable JAR Modify a Gradle jar task 1 [..] 2 jar { 3 manifest { 4 attributes Implementation - Title : Gradle Demo Application, 5 Implementation - Version : version, 6 Main - Class : hu. qwaevisz. hello. Application 7 } 8 } 9 10 task run ( type : Exec ) { 11 workingdir build / libs 12 commandline java, -jar, "${ project. name }-${ version }. jar " 13 } build.gradle 1 > gradle clean build run 2 3 [..] 4 5 > Task : run 6 Hello World 7 8 BUILD SUCCESSFUL in 2s 9 6 actionable tasks : 6 executed Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 21 / 27

Gradle TestNG integration 1 [..] 2 def testngversion = 6.9.10 3 4 repositories { mavencentral () } 5 6 dependencies { 7 testcompile group : org. testng, name : testng, version : testngversion 8 } 9 10 test { Default test framework: junit. 11 usetestng () 12 } build.gradle 1 > gradle test 2 [..] 3 > Task : test 4 5 Gradle suite > Gradle test > hu. qwaevisz. hello. ApplicationTest. addnumbers FAILED 6 java.lang. AssertionError at ApplicationTest.java :11 7 8 1 test completed, 1 failed 9 [..] 10 BUILD FAILED in 1s 11 3 actionable tasks : 3 executed Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 22 / 27

Gradle Java plugin Tasks https://docs.gradle.org/current/userguide/java_plugin.html Task: compilejava, compiletestjava, jar, javadoc, test, clean,... Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 23 / 27

Gradle Java plugin Dependency Configurations compile Compile and runtime dependency. compileonly Dependency only for compilation. runtime Runtime dependency. testcompile Additional compile and runtime dependency for tests (test task). testruntime Additional runtime dependency for tests (test task). archives The artifactory of the project (e.g. jar)...... Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 24 / 27

Gradle Eclipse integration 1 [..] 2 apply plugin : eclipse 3 [..] build.gradle 1 > gradle eclipse Additional tasks: eclipseclasspath, eclipsejdt, eclipseproject Directory structure settings/ org.eclipse.jdt.core.prefs.classpath.project Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 25 / 27

Eclipse Gradle project File Import... Gradle Existing Gradle Project Project root directory: \helloworld Import options: Gradle wrapper Where do I execute Gradle s tasks? The Eclipse s Gradle plugin (buildship) is good to organize the Gradle project, but you can execute any Gradle tasks inside Eclipse after install that plugin. But I suggest to execute Gradle tasks via a separate terminal, without Eclipse IDE. Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 26 / 27

Gradle IntelliJ integration 1 [..] 2 apply plugin : idea 3 [..] build.gradle 1 > gradle idea További taskok: cleanidea, ideamodule, ideaproject, ideaworkspace Directory structure helloworld.iml helloworld.ipr helloworld.iws Dávid Bedők (UNI-OBUDA) Hello JavaEE 2017.09.18. v0.2 27 / 27