miércoles, 12 de mayo de 2021

45. Converting the project to Gradle

1. The process

 1. Create a new folder in the WorkSpace (MyWorkspace) for instance AEVaadin-20-01

2. Copy these files and folders from the last post project VaadinGradle02

  Files: build.gradle, gradle.properties, LICENSE (optional), README.md

  Folders: frontend, src.



3. Now import an existing gradle project , and select the folder (for instance in this example P0-AEVaadin-19-04). Select gradle version 6.6 7.1.1and the Java home












Perhaps there can be error. So review the Java Build Path in properties, and select the correct JDK 



Verify that the gradle.properties has this content:

#vaadinVersion=19.0.4  //Not used

vaadinVersion=20.0.6

Refresh project F5 

Gradle-> Regresh gradle poject


A. Now to see if it works change int the file build.gradle the variable productionMode to false and:

1. From Gradle Tasks tab -> "Your Project Name" -> build -> (clean and then build) and verify that the war was generated

2. Run as Run on Server and verify it runs


B. Now repeat the proces to see if it can generate the war file for production. Change in the build.gradle file the  variable  productionMode to false and:

1. From Gradle Tasks tab -> "Your Project Name" -> build -> (clean and then build) and verify that the war was generated

2. Copy the war to aTomvat webapp folder and try to deploy it

Here is an example of working build.gradle


// New in the Vaadin starting project version 19+
buildscript {
    repositories {
        maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
    }
}

plugins {
    id 'war'                                 //Generate a ".war" file
    id 'org.gretty' version '3.0.4'
    //id 'com.vaadin' version '20.0.0.alpha6'
    id 'com.vaadin' version '20.0.6'
    id 'java-library'  // only to admit "api" instead of "0.
}

defaultTasks("clean", "build")

repositories {
    mavenCentral()
    maven { url = "https://maven.vaadin.com/vaadin-addons" }

    jcenter() // jcenter is deprecated, however the Gretty plugin still uses stuff from jcenter: https://github.com/gretty-gradle-plugin/gretty/issues/192
}



project.war.destinationDirectory = file("$rootDir/../mytargets")  
project.archivesBaseName = 'p-aevaadin' 
project.version = '2.0'

gretty {
    contextPath = "/"  // it points to https://localhost:8080/
    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  //Not included in the starting-project generation 
    optimizeBundle = true
}

dependencies {
    // $vaadinVersion" is defined in gradle.properties
    implementation enforcedPlatform("com.vaadin:vaadin-bom:$vaadinVersion")

    // Vaadin
    //implementation("com.vaadin:vaadin-core")
    implementation("com.vaadin:vaadin")
    implementation("com.vaadin:vaadin-cdi")
    
    
    
    //providedCompile "javax.servlet:javax.servlet-api:3.1.0"   //generated by starting-project
    
    //Use only or jakarta.servet or jakarta.platform but not both at the same time --> genarate errors : The package jakarta.mail is accessible from more than one module: <unnamed>, jakarta.mail
    providedCompile "jakarta.servlet:jakarta.servlet-api:5.0.0" //replace javax by jakarta !!!!! 
    //providedCompile "jakarta.platform:jakarta.jakartaee-api:9.0.0" //replace javax by jakarta !!!!! 

    providedCompile "jakarta.annotation:jakarta.annotation-api:2.0.0"
    providedCompile "jakarta.activation:jakarta.activation-api:2.0.1"
    
    implementation "com.sun.activation:jakarta.activation:2.0.1"
    

    // 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"
    
    //=============LOMBOK BEGIN ============================
    // Not generated by the Vaadin starting-project
    compileOnly 'org.projectlombok:lombok:1.18.20'
    annotationProcessor 'org.projectlombok:lombok:1.18.20'
	
    testCompileOnly 'org.projectlombok:lombok:1.18.20'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
    //=============LOMBOK END ==============================
    
	// This dependency is for local jars in the folder mylibs
    //implementation files(
    api files(
    	'../mytargets/a-annotations-1.0.jar', 
    	'../mytargets/a-basic-utils-1.0.jar', 
    	'../mytargets/a-report-utils-1.0.jar',
    	'../mytargets/b-base-control-model-1.0.jar', 
    	'../mytargets/b-other-utils-1.0.jar',
    	'../mytargets/c-dao-1.0.jar',
    	'../mytargets/c-model-aytos-1.0.jar',
    	//'../mytargets/c-model-castilla-1.0.jar',
    	//'../mytargets/c-model-eni-1.0.jar',
    	'../mytargets/c-model-gexflow-1.0.jar',
    	//'../mytargets/c-model-orve-1.0.jar',
    	'../mytargets/c-vaadin-basic-1.0.jar' )      
    
    implementation "org.jboss.weld.servlet:weld-servlet-shaded:3.1.7.Final"
    
    implementation "org.javassist:javassist:3.27.0-GA"
    
    /* HIbernate */
    implementation "org.hibernate:hibernate-core:5.4.31.Final"
    implementation "org.hibernate:hibernate-envers:5.4.31.Final"
    //implementation "org.hibernate:hibernate-testing:5.4.31.Final"
    implementation "org.hibernate:hibernate-validator:7.0.1.Final" 
    
    /*DB Drivers */
    runtimeOnly "com.h2database:h2:1.4.200"
    implementation "org.postgresql:postgresql:42.2.20"
    implementation "net.sourceforge.jtds:jtds:1.3.1"
    
    /* Apache CMIS */
    implementation "org.apache.chemistry.opencmis:chemistry-opencmis-client-impl:1.1.0"
    
    /* JASPER REPORTS */
    implementation "net.sf.jasperreports:jasperreports:6.16.0"
    /* IText VELL pero el vol jasper reports*/
    implementation "com.lowagie:itext:2.1.7"
    implementation "com.itextpdf:itext7-core:7.1.15"  //Falta "type pom" ?????
    
}


2. File structure

Important locations:

src/main/webapp/META-INF/context.xml (For JNDI pool of connections)

src/main/resources/META-INF/presistence.xml 

src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener

frontend/styles

frontend/font-awesome

gradle.build

gradle.properties


src
   |->main
   |   |->webapp
   |   |   |->WEB-INF       Not used (can be deleted)
   |   |   |   |->beans.xml Not used 
   |   |   |->skins
   |   |   |   |->ui
   |   |   |   |->content
   |   |   |->META-INF
   |   |   |   |>context.xml (JNDI pool of connections)
   |   |   |->imgs
   |   |   |   |->enterprise (or any particular folder with images)
   |   |   |->icons
   |   |   |   |->flags (or any particular folder with icons)
   |   |->resources
   |   |   |->view (in yaml or any partiular folder with some info)
   |   |   |->reports (or any partiular folder with jasper reports)
   |   |   |->readme (or any partiular folder with some info)
   |   |   |->properties (property files)
   |   |   |->META-INF
   |   |   |   |->services
   |   |   |      |->com.vaadin.flow.server.VaadinServiceInitListener
   |   |   |   |->persistence.xml
   |   |   |->i18n (all teh internationalization resources)
   |   |   |   |->file_en.properties ; file_es.properties
   |   |   |->docs (any doc )
   |   |   |->simplelogger.properties
   |   |->java 
   |   |   |->ui
   |   |   |->openadmin
   |->test
frontend
   |->tone-edu (test with js)
   |   |->tone-test.js
   |->three-edu (test with js)
   |   |->three-test.js
   |->apex-charts (test with js)
   |   |->apex-charts-test.js
   |->styles (all the css defined)
   |   |->my-defined.css.css
   |->src (empty)
   |->generated
   |   |->vaadin.ts
   |->font-awesome
   |   |->webfonts, svgs, sprites, scss, metadata, less, js, css..
gradle.properties
build.gradle


No hay comentarios:

Publicar un comentario