martes, 11 de mayo de 2021

43. Using Gradle. The starting project from Vaadin (1)

This super-useful Vaadin guide is applied. Eclipse is used. These are the  main steps:

1. Create a Vaadin 19+ Gradle Project

The starter project is in https://github.com/vaadin/base-starter-gradle

Click in the branches to select master branch


Click in the master branch


Verify that the master branch is selected and download the project


Download ZIP



Now open the zip and copy the "base-starter-gradle-master" folder to an Eclipse Workspace, and change the name for instance to VaadinGradle02


Now from Eclipse click in File->Import->Gradle(folder)->Existing Gradle Project

You get a welcome window


Click Next



Select  Gradle 6.6 Gradle 7.1.1 and a jdk15 compatible and click Next


Now in the last window click Finish.


and in the Project Explorer you can see:


2. Verify the Java version


Now you should change the java version if it is not 15 (in this case it is java 13)

In the Project Explorer, right-click the project and in Properties select Java BUild Path. In my case it points Java version 13


Click on the JRE line and click Edit.


Change all to Java v15


 

then click on Apply and Close Button


3. Compile and Execute the project

1. Right-click on the project and select Gradle -> Refresh Gradle Project

2. Optionally in the Gradle Tasks window open the build folder and double click the build task. This task, although is not necessary, may show possible errors. 


3. In the Gradle Tasks window open the gretty folder and double click in the appRun task


4. After a while open a browser and point to http://localhost:8080/  and here is the result


5. To stop the server, goto to the Console window in Eclipse and press any key

4. Run on Tomcat (problems with gretty version >3.04)

1. Make sure you have installed a Tomcat 9 in the servers window

2. In the Gradle Tasks window open the build folder and double click the build task.

3. Right-click the project and Run AS -> Run on Server 

4. Open a Chrome tab and point to http://localhost:8080/VaadinGradle02/

5. Solving problems (Vaadin 22.0.4)

1. Add procutionMode = false and optimizedBundle = true to the vaadin section (lines 30-31)

2. Delete file settings.gradle and change line 11 as shown

3. Line 39-40 migrate from "javax" to "jakarta" packages



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
buildscript {
    repositories {
        maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
        maven { url "https://plugins.gradle.org/m2/" }
    }
}

plugins {
    id 'war'
    id 'org.gretty' version '3.0.6'
    id 'com.vaadin' version "${vaadinVersion}"
}

defaultTasks("build")

repositories {
    mavenCentral()
}

gretty {
    contextPath = "/"
    servletContainer = "jetty9.4"
}

// The following pnpmEnable = true is not needed as pnpm is used by default,
// this is just an example of how to configure the Gradle Vaadin Plugin:
// for more configuraion options please see: https://vaadin.com/docs/latest/guide/start/gradle/#all-options
vaadin {
    pnpmEnable = true
    productionMode = false  //1.Ximo
    optimizeBundle = true   //2.Ximo
}

dependencies {
    implementation enforcedPlatform("com.vaadin:vaadin-bom:$vaadinVersion")

    // Vaadin
    implementation("com.vaadin:vaadin-core")
    //providedCompile "javax.servlet:javax.servlet-api:3.1.0" //3.a.Ximo
    compileOnly 'jakarta.servlet:jakarta.servlet-api:5.0.0'   //3.b.Ximo
    // logging
    // currently we are logging through the SLF4J API to SLF4J-Simple. See src/main/resources/simplelogger.properties file for the logger configuration
    implementation "org.slf4j:slf4j-simple:1.7.30"
}

No hay comentarios:

Publicar un comentario