miércoles, 12 de mayo de 2021

44. Using Gradle. The starting project from Vaadin (2). Adjusting the buid.gradle file

 1. The build.gradle file

Here is the generated file with some add-ons for:
  • using Lombok facilities to reduce boilerplate
  • migrating from javax to Jakarta

// 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' '20.0.6' //Change
}

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
}

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

// For enabling the generation of the ".war" file 
// This entry is Not generated in the starting-project generation 
// Usually used for production
/*
war {
	enabled = true
}
*/

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 = true  //Not included in the starting-project generation 
    optimizeBundle= "true" //Change
}
dependencies { implementation enforcedPlatform("com.vaadin:vaadin-bom:$vaadinVersion") // Vaadin //implementation("com.vaadin:vaadin-core")
    implementation("com.vaadin:vaadin")       //Change
    implementation("com.vaadin:vaadin-cdi")   //Change 

    //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 "javax.servlet:javax.servlet-api:3.1.0" //generated by starting-project providedCompile "jakarta.servlet:jakarta.servlet-api:5.0.0" //replace javax by jakarta !!!!!
    // 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 ==============================


    //=============MY PERSDONAL DEPENDENCIES============================
    / 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-gexflow-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-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" ?????
    
    
    providedCompile "jakarta.activation:jakarta.activation-api:2.0.1"
    
    implementation "com.sun.activation:jakarta.activation:2.0.1"
    //=============MY PERSDONAL DEPENDENCIES END============================

    
}


2. Run in Tomcat

  • Create the Tomcat 9 server, (using for instance the Servers Window)
  • Make sure Jetty is not running (press any key in the Console window and click the red square button if active)
  • Right-Click the project Run As-> Run On Server
  • Wait a moment and it works in
http://localhost:8080/VaadinGradle02/

IMPORTANT: The context is now VaadinGradle02 and not "/" as in jetty

3. Create the war file


1. Uncomment these lines:  (Should be commented!!)

    war {
       enabled = true
  }

and uncomment this one too.

   productionmode = true  (If you do not choose the correct version, the production of the war may fail!!)
If you don't uncomment the line of the "production mode=true", the generated war will only work in the computer you have developed the war, as the war is able to find the source code for debugging, but the war will be looking for the source code if you deploy it in another computer and it will stop execution!

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

3. Now the war file is in the build/libs folder



4. If you have choosed the option project.war.destinationDirectory = file("$rootDir/../mytargets")
then the output will be in mytargets directory!
 

No hay comentarios:

Publicar un comentario