jhipster / generator-jhipster-micronaut

Micronaut blueprint for JHipster
Apache License 2.0
98 stars 27 forks source link

Heroku deployment via gradle #240

Open atomfrede opened 3 years ago

atomfrede commented 3 years ago
Overview of the issue

Deploying an app to heroku with gradle does not work out of box. Using git deployment seems to have no resources/frontend build, although the build is executed. Deploying via jar method does not build a correct shadow/executable jar, such that the frontend is not contained in the jar.

Doing ./gradlew assemble && heroku deploy:jar build/libs/*-all.jar works fine.

Reproduce the error

Use the following JDL

application {
  config {
    applicationType monolith
    baseName HelloMHipster
    packageName hello.mhipster
    clientTheme cyborg,
    clientThemeVariant primary,
    authenticationType oauth2
    prodDatabaseType postgresql
    buildTool gradle
    cacheProvider caffeine
    testFrameworks [protractor]
    languages [en, de, fr]
  }
  entities *
}

entity Fish {
    name String required minlength(3)
    age Integer required min(0)
    waterType WaterType required
    picture Blob
}

entity School {
    name String required
}

enum WaterType {
    SALT, FRESH
}

relationship ManyToOne {
  Fish{school(name)} to School
}
paginate Fish, School with pagination

and do mhipster import-jdl jhipster.jdl && mhipster heroku and use jar deployment.

Suggest a Fix

When doing jar deployment the wrong task seems to be executed as no shadow jar is created during that process and so the wrong jar is uploaded.

Project configuration
JHipster Version(s)
hello-m-hipster@0.0.1-SNAPSHOT /home/fred/git/github/jhipster/samples/mhipster-heroku-gradle-jar
├─┬ generator-jhipster-micronaut@1.0.0
│ └── generator-jhipster@6.10.5
└── generator-jhipster@6.10.5
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "authenticationType": "oauth2",
    "cacheProvider": "caffeine",
    "clientFramework": "angularX",
    "serverPort": "8080",
    "serviceDiscoveryType": false,
    "skipUserManagement": true,
    "baseName": "HelloMHipster",
    "buildTool": "gradle",
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "jhiPrefix": "jhi",
    "languages": ["en", "de", "fr"],
    "messageBroker": false,
    "nativeLanguage": "en",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "skipClient": false,
    "testFrameworks": ["protractor"],
    "websocket": false,
    "applicationType": "monolith",
    "packageName": "hello.mhipster",
    "packageFolder": "hello/mhipster",
    "clientTheme": "cyborg",
    "clientThemeVariant": "primary",
    "jhipsterVersion": "6.10.5",
    "creationTimestamp": 1618812240696,
    "skipServer": false,
    "clientPackageManager": "npm",
    "useSass": true,
    "embeddableLaunchScript": false,
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [
      {
        "name": "generator-jhipster-micronaut",
        "version": "1.0.0"
      }
    ],
    "blueprints": [
      {
        "name": "generator-jhipster-micronaut",
        "version": "1.0.0"
      }
    ],
    "herokuAppName": "limitless-journey-92398",
    "herokuDeployType": "jar",
    "herokuJavaVersion": "11",
    "useOkta": true,
    "oktaAdminLogin": "frederik.hahne@jhipster.tech",
    "oktaAdminPassword": "yxMB675m3BRdS8ZQ"
  },
  "entities": ["Fish", "School"]
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Fish {
  name String required minlength(3),
  age Integer required min(0),
  waterType WaterType required,
  picture AnyBlob
}
entity School {
  name String required
}
enum WaterType {
  SALT,
  FRESH
}

relationship ManyToOne {
  Fish{school(name)} to School
}

paginate Fish, School with pagination

Environment and Tools

openjdk version "11.0.10" 2021-01-19 OpenJDK Runtime Environment (build 11.0.10+9) OpenJDK 64-Bit Server VM (build 11.0.10+9, mixed mode)

git version 2.31.1

node: v14.16.0

npm: 7.6.1

yarn: 1.22.10

Docker version 20.10.6, build 370c28948e

docker-compose version 1.29.1, build unknown

atomfrede commented 3 years ago

Two things to notice:

So I will try to add change the build command and try to make sure there is only one jar in build/libs afterwards, so most likely a dedicated command.

When thinking about it, maybe that is also the problem with the git deployment. There are multiple jars in build/libs and somehow heroku needs to choose one. Guess also the first, which is not the shadow jar.

poornerd commented 3 years ago

Yes, I have hadn't noticed yet either that I would have a problem as soon as I bump the version with potentially having multiple jars. I suppose the workaround could be to add "clean" to the build command?

./gradlew clean assemble && heroku deploy:jar build/libs/*-all.jar

atomfrede commented 3 years ago

For the multiple jar thing I have a PR already. There seems to be a problem with the git deployment, regarding the frontend build https://github.com/jhipster/generator-jhipster-micronaut/pull/241/files