jhipster / generator-jhipster-micronaut

Micronaut blueprint for JHipster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compilation error when creating app with blog-oauth2 JDL

mraible opened this issue · comments

Overview of the issue

Creating an app with the blog-oauth2 JDL results in a compilation error.

jhipster jdl blog-oauth2 --blueprints micronaut

Run ./mvnw after the process completes. You'll see the following errors:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project blog: Compilation failure: Compilation failure:
[ERROR] /Users/mraible/Downloads/micronaut/src/main/java/com/jhipster/demo/blog/web/rest/PostResource.java:[59,6] incompatible types: com.jhipster.demo.blog.domain.Post cannot be converted to java.lang.annotation.Annotation
[ERROR] /Users/mraible/Downloads/micronaut/src/main/java/com/jhipster/demo/blog/config/CacheConfiguration.java:[25,31] cannot find symbol
[ERROR]   symbol:   variable cacheManager
[ERROR]   location: class com.jhipster.demo.blog.config.CacheConfiguration
[ERROR] /Users/mraible/Downloads/micronaut/src/main/java/com/jhipster/demo/blog/config/CacheConfiguration.java:[26,16] cannot find symbol
[ERROR]   symbol:   variable cacheManager
[ERROR]   location: class com.jhipster.demo.blog.config.CacheConfiguration
[ERROR] -> [Help 1]
Reproduce the error

Install Micronaut for JHipster 0.8.0, then run the commands above.

Related issues

I also saw a lot of downloads from jcenter.bintray.com when creating the app. We should probably fix that before it goes away on May 31, 2021.

JHipster Version(s)
blog@0.0.1-SNAPSHOT /Users/mraible/Downloads/micronaut
├── generator-jhipster@6.10.5
└─┬ generator-jhipster-micronaut@0.8.0
  └── generator-jhipster@6.10.5  deduped

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "authenticationType": "oauth2",
    "cacheProvider": "hazelcast",
    "clientFramework": "angularX",
    "serverPort": "8080",
    "serviceDiscoveryType": false,
    "skipUserManagement": true,
    "baseName": "blog",
    "buildTool": "maven",
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "jhiPrefix": "jhi",
    "languages": ["en", "fr"],
    "messageBroker": false,
    "nativeLanguage": "en",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "skipClient": false,
    "testFrameworks": ["protractor"],
    "websocket": false,
    "applicationType": "monolith",
    "packageName": "com.jhipster.demo.blog",
    "packageFolder": "com/jhipster/demo/blog",
    "jhipsterVersion": "6.10.5",
    "creationTimestamp": 1612929300087,
    "skipServer": false,
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "useSass": true,
    "embeddableLaunchScript": false,
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [
      {
        "name": "generator-jhipster-micronaut",
        "version": "0.8.0"
      }
    ],
    "blueprints": [
      {
        "name": "generator-jhipster-micronaut",
        "version": "0.8.0"
      }
    ]
  },
  "entities": ["Blog", "Post", "Tag"]
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Blog {
  name String required minlength(3),
  handle String required minlength(2)
}
entity Post {
  title String required,
  content TextBlob required,
  date Instant required
}
entity Tag {
  name String required minlength(2)
}
relationship ManyToOne {
  Blog{user(login)} to User,
  Post{blog(name)} to Blog
}
relationship ManyToMany {
  Post{tag(name)} to Tag{entry}
}

paginate Post, Tag with infinite-scroll

Environment and Tools

openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)

git version 2.24.3 (Apple Git-128)

node: v14.15.0

npm: 6.14.11

yeoman: 3.1.1

yarn: 1.22.10

Docker version 20.10.2, build 2291f61

docker-compose version 1.27.4, build 40524192

identical .jhipster/Blog.json
identical .jhipster/Post.json
identical .jhipster/Tag.json
INFO! Congratulations, JHipster execution is complete!

The first error, from PostResource happens because Micronaut has a @Post annotation and the entity's name is Post. I changed all references to the Post entity to com.jhipster.demo.blog.domain.Post and it fixed the problem. For example:

@Post("/posts")
@ExecuteOn(TaskExecutors.IO)
public HttpResponse<com.jhipster.demo.blog.domain.Post> createPost(@Body com.jhipster.demo.blog.domain.Post post) throws URISyntaxException {
    log.debug("REST request to save Post : {}", post);
    if (post.getId() != null) {
        throw new BadRequestAlertException("A new post cannot already have an ID", ENTITY_NAME, "idexists");
    }
    com.jhipster.demo.blog.domain.Post result = postRepository.mergeAndSave(post);
    URI location = new URI("/api/posts/" + result.getId());
    return HttpResponse.created(result).headers(headers -> {
        headers.location(location);
        HeaderUtil.createEntityCreationAlert(headers, applicationName, true, ENTITY_NAME, result.getId().toString());
    });
}

The CacheConfiguration compilation issue seems to come from cacheProvider hazelcast in the JDL. If I change it to ehcache, it works.

It seems like the jdl command should some sort of validation to make sure the values are valid for a blueprint?

Good point, I think we don't do something to validate the jdl. For the @Post vs Post-Entity, do you think we should add that to protected words/names or import e.g. @Post fully qualified so there will be no clash with any user defined entity name?

@mraible Can you check it works now when changing to a supported cache provider out of box? Will track the sanity check for JDL configuration options in a dedicated issue.

Tried with v7 main branch and it fails. I knew it would, but figured I'd document the error here in case someone is searching for it. 🙂

Error running generator app: TypeError: jhContext.setupServerOptions is not a function
TypeError: jhContext.setupServerOptions is not a function

After installing generator-jhipster@6.10.5, and using npm link in a fresh checkout, I can confirm everything compiles. 👍

However, the tests do not pass, nor does the app startup.

Caused by: org.hibernate.cache.CacheException: Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory
	at org.hibernate.cache.internal.RegionFactoryInitiator.resolveRegionFactory(RegionFactoryInitiator.java:89)
	at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:47)
	at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:32)
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)

What should I change cacheProvider too? It's currently set to hazelcast.

Currently ehcache, caffeine and redis are supported.

I updated blog-oauth2.jdl to use Ehcache. Now I'm able to start it!

FWIW, npm run e2e fails, but I've seen this on the main generator too, so probably not related to Micronaut.

> blog@0.0.1-SNAPSHOT e2e /Users/mraible/blog
> protractor src/test/javascript/protractor.conf.js

[10:47:52] W/configParser - pattern ./e2e/entities/**/*.spec.ts did not match any files.
[10:47:52] I/launcher - Running 1 instances of WebDriver
[10:47:52] I/direct - Using ChromeDriver directly...
[10:47:52] E/runner - Unable to start a WebDriver session.
[10:47:52] E/launcher - Error: Error: spawn Unknown system error -86
    at ChildProcess.spawn (internal/child_process.js:403:11)
    at Object.spawn (child_process.js:553:9)
    at exec (/Users/mraible/blog/node_modules/selenium-webdriver/io/exec.js:116:27)
    at /Users/mraible/blog/node_modules/selenium-webdriver/remote/index.js:219:25
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
[10:47:52] E/launcher - Process exited with error code 100
npm ERR! code ELIFECYCLE
npm ERR! errno 100
npm ERR! blog@0.0.1-SNAPSHOT e2e: `protractor src/test/javascript/protractor.conf.js`
npm ERR! Exit status 100
npm ERR!
npm ERR! Failed at the blog@0.0.1-SNAPSHOT e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mraible/.npm/_logs/2021-03-16T16_47_52_614Z-debug.log

It looks like no e2e spec files have been generated

e2e files exist:

➜  blog git:(master) ls src/test/javascript
e2e                  jest.conf.js         protractor.conf.js
jest-global-mocks.ts jest.ts              spec
➜  blog git:(master) ls src/test/javascript/e2e
account      admin        page-objects
➜  blog git:(master) ls src/test/javascript/e2e/account
account.spec.ts
➜  blog git:(master) ls src/test/javascript/e2e/admin
administration.spec.ts
➜  blog git:(master) ls src/test/javascript/e2e/page-objects
jhi-page-objects.ts

Let's close this as the compilation error is fixed. We will tackle the jdl validation in a different issue after jh7 migration.