Skip to content

Commit

Permalink
Merge pull request jhipster#1 from jeremyg484/micronaut-3
Browse files Browse the repository at this point in the history
Micronaut 3 Updates and Fixes
  • Loading branch information
kevintanhongann authored Aug 8, 2023
2 parents 2690e5e + 146e128 commit c5b32ea
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 126 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,51 @@
> This project is a [Micronaut](https://micronaut.io) blueprint for [JHipster](https://jhipster.tech).
> While we are working to create a complete experience, there are likely some gaps.
> Please [let us know](https://github.com/jhipster/generator-jhipster-micronaut/issues) if you encounter issues.
>
## Installing and Using the Active Development Version

This currently active development branch is based on the latest production release of JHipster - v7.9.3

As a pre-requisite, you must have NodeJS v16.x installed, along with the bundled version of NPM.

1. Start by installing JHipster v7.9.3 with

```
npm install -g generator-jhipster
```

2. Then install this in-development blueprint by
```
git clone https://github.com/jeremyg484/generator-jhipster-micronaut.git
cd generator-jhipster-micronaut
git checkout micronaut-3
npm link generator-jhipster
npm install
npm link
```

3. Next you can create a new application with the development version of this blueprint by executing:
```
mkdir my-project
cd my-project
npm link "generator-jhipster-micronaut"
mhipster --skip-jhipster-dependencies
```

This will execute the mhipster CLI tool that walks you through a series of steps to generate the code for your application.

Alternatively, you can generate an application based on one of the samples in https://github.com/jhipster/jdl-samples

For example, to generate a default gradle-based application, execute:

```
mkdir my-jdl-project
cd my-jdl-project
npm link "generator-jhipster-micronaut"
mhipster jdl default-gradle --skip-jhipster-dependencies
```

You will re-execute the commands in step 3 for any new application that you would like to generate with this in-development version.

# Greetings, Micronaut Hipster!

Expand Down
7 changes: 4 additions & 3 deletions generators/constants.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ module.exports = {
},
},
versions: {
micronaut: '3.9.1',
micronaut: '3.9.5',
micronautData: '3.10.0',
micronautOpenApi: '2.3.1',
micronautOpenApi: '4.8.7',
rxJava3: '2.3.0',
hibernate: '5.5.9.Final',
hibernate: '5.6.15.Final',
prometheusSimpleclient: '0.16.0',
jackson: '2.13.3',
javassist: '3.27.0-GA', // Should match Hibernate deps
javaxMail: '2.0.1',
Expand Down
24 changes: 10 additions & 14 deletions generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,13 @@ dependencies {
// import JHipster dependencies BOM
if (!project.hasProperty("gae")) {
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")
annotationProcessor platform("io.micronaut:micronaut-bom:${micronautVersion}")
implementation platform("io.micronaut:micronaut-bom:${micronautVersion}")
}

annotationProcessor "io.micronaut:micronaut-validation"
<%_ if (databaseType === 'sql') { _%>
annotationProcessor "io.micronaut.data:micronaut-data-processor:$micronaut_data_version"
annotationProcessor "io.micronaut.data:micronaut-data-processor"
<%_ } _%>
annotationProcessor "io.micronaut.openapi:micronaut-openapi:$micronaut_openapi_version"
annotationProcessor "io.micronaut.openapi:micronaut-openapi"

// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
Expand Down Expand Up @@ -387,12 +385,12 @@ dependencies {
liquibaseRuntime sourceSets.main.compileClasspath
<%_ } _%>

implementation "io.micronaut:micronaut-inject:$micronautVersion"
implementation "io.micronaut:micronaut-validation:$micronautVersion"
implementation "io.micronaut:micronaut-runtime:$micronautVersion"
implementation "io.micronaut:micronaut-http-client:$micronautVersion"
implementation "io.micronaut:micronaut-http-server-netty:$micronautVersion"
implementation "io.micronaut:micronaut-management:$micronautVersion"
implementation "io.micronaut:micronaut-inject"
implementation "io.micronaut:micronaut-validation"
implementation "io.micronaut:micronaut-runtime"
implementation "io.micronaut:micronaut-http-client"
implementation "io.micronaut:micronaut-http-server-netty"
implementation "io.micronaut:micronaut-management"
implementation "io.micronaut.security:micronaut-security-jwt"
<%_ if (authenticationType == 'oauth2') { _%>
implementation "io.micronaut.security:micronaut-security-oauth2"
Expand Down Expand Up @@ -527,10 +525,8 @@ dependencies {
<%_ } _%>

// Micronaut test deps
testAnnotationProcessor platform("io.micronaut:micronaut-bom:$micronautVersion")
testAnnotationProcessor "io.micronaut.data:micronaut-data-processor:$micronaut_data_version"
testAnnotationProcessor "io.micronaut.data:micronaut-data-processor"
testAnnotationProcessor "org.glassfish.jaxb:jaxb-runtime:$jaxb_runtime_version"
testImplementation platform("io.micronaut:micronaut-bom:$micronautVersion")
testImplementation "io.micronaut.test:micronaut-test-junit5"

testImplementation "org.junit.jupiter:junit-jupiter-engine"
Expand Down Expand Up @@ -560,7 +556,7 @@ dependencies {
testImplementation "org.testcontainers:kafka"
<%_ } _%>

implementation("io.micronaut.rxjava3:micronaut-rxjava3:$rxJava3Version")
implementation("io.micronaut.rxjava3:micronaut-rxjava3")
implementation("io.micronaut.rxjava3:micronaut-rxjava3-http-client:$rxJava3Version")

//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
Expand Down
2 changes: 1 addition & 1 deletion generators/server/templates/gradle.properties.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jaxb_runtime_version=2.3.2
<%_ } _%>

# gradle plugin version
micronaut_plugin_version=3.5.1
micronaut_plugin_version=3.7.9
git_properties_plugin_version=2.4.1
<%_ if (!skipClient) { _%>
gradle_node_plugin_version=2.2.4
Expand Down
5 changes: 2 additions & 3 deletions generators/server/templates/gradle/docker.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dockerfile {
baseImage = "openjdk:15-alpine"
args("-Xmx128m")
}

dockerBuild {
images = ["<%= baseName %>:$project.version", "<%= baseName %>:latest"]
}
Expand All @@ -17,9 +18,7 @@ dockerfileNative {
baseImage = "oracle/graalvm-ce:20.3.0-java11"
args("-Xmx64m")
}
<!-- nativeImage { -->
<!-- args('--static') -->
<!-- } -->

dockerBuildNative {
images = ["<%= baseName %>:$project.version", "<%= baseName %>:latest"]
}
50 changes: 32 additions & 18 deletions generators/server/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ _%>
<packaging>jar</packaging>
<name><%= humanizedBaseName %></name>

<parent>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-parent</artifactId>
<version><%= versions.micronaut %></version>
</parent>

<repositories>
<!-- jhipster-needle-maven-repository -->
<%_ if (JHIPSTER_DEPENDENCIES_VERSION.endsWith('-SNAPSHOT')) { _%>
Expand All @@ -34,8 +40,10 @@ _%>
<properties>
<!-- Build properties -->
<exec.mainClass><%=packageName%>.<%=mainClass%></exec.mainClass>
<maven.version>3.3.9</maven.version>
<micronaut.runtime>netty</micronaut.runtime>
<java.version><%= JAVA_VERSION %></java.version>
<jdk.version><%= JAVA_VERSION %></jdk.version>
<release.version><%= JAVA_VERSION %></release.version>
<%_ if (!skipClient) { _%>
<node.version>v<%= NODE_VERSION %></node.version>
<%_ if (clientPackageManager === 'npm') { _%>
Expand Down Expand Up @@ -63,6 +71,7 @@ _%>
<micronaut.version><%= versions.micronaut %></micronaut.version>
<micronaut-data.version><%= versions.micronautData %></micronaut-data.version>
<micronaut-openapi.version><%= versions.micronautOpenApi %></micronaut-openapi.version>
<prometheus-simpleclient.version><%= versions.prometheusSimpleclient %></prometheus-simpleclient.version>
<hibernate.version><%= versions.hibernate %></hibernate.version>
<!-- The javassist version should match the one managed by
https://mvnrepository.com/artifact/org.hibernate/hibernate-core/${hibernate.version} -->
Expand Down Expand Up @@ -118,12 +127,12 @@ _%>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<scope>import</scope>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-bom</artifactId>
<version>${micronaut.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.github.jhipster</groupId>
Expand All @@ -133,13 +142,6 @@ _%>
<scope>import</scope>
</dependency>
<!-- jhipster-needle-maven-add-dependency-management -->
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-bom</artifactId>
<version>${micronaut.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -485,11 +487,6 @@ if (devDatabaseType === 'postgresql' || prodDatabaseType === 'postgresql') { _%>
<scope>compile</scope>
</dependency>
<%_ } _%>
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>${javax-mail.version}</version>
</dependency>
<dependency>
<groupId>io.micronaut.test</groupId>
<artifactId>micronaut-test-junit5</artifactId>
Expand Down Expand Up @@ -521,10 +518,20 @@ if (devDatabaseType === 'postgresql' || prodDatabaseType === 'postgresql') { _%>
<artifactId>jakarta.mail</artifactId>
<version>${javax-mail.version}</version>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
<version>${javax-mail.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>${prometheus-simpleclient.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
Expand Down Expand Up @@ -586,6 +593,8 @@ if (devDatabaseType === 'postgresql' || prodDatabaseType === 'postgresql') { _%>
<target>${java.version}</target>
<compilerArgs>
<arg>-parameters</arg>
<arg>-Amicronaut.processing.group=<%= packageName %></arg>
<arg>-Amicronaut.processing.module=<%= dasherizedBaseName %></arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
Expand All @@ -599,6 +608,11 @@ if (devDatabaseType === 'postgresql' || prodDatabaseType === 'postgresql') { _%>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class <%= mainClass %> {

ApplicationContext context = Micronaut.build(args)
.mainClass(<%= mainClass %>.class)
.deduceEnvironment(false)
.environments(environments.toArray(new String[0]))
.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ActiveProfilesInfoSource implements InfoSource {
@Override
public Publisher<PropertySource> getSource() {
HashMap<String, Object> map = new HashMap<>(1);
map.put("activeProfiles", environment.getActiveNames());
map.put("active-profiles", environment.getActiveNames());
return Publishers.just(PropertySource.of("active-profiles", map));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package <%=packageName%>.config;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;

import <%=packageName%>.util.JHipsterProperties;
Expand All @@ -13,18 +11,12 @@ import java.time.Duration;
import org.ehcache.config.builders.*;
import org.ehcache.jsr107.Eh107Configuration;
import org.ehcache.jsr107.EhcacheCachingProvider;
<%_ if (enableHibernateCache) { _%>
import org.hibernate.cache.jcache.ConfigSettings;
<%_ } _%>
<%_ } _%>
<%_ if (cacheProvider === 'caffeine') { _%>
import com.github.benmanes.caffeine.jcache.spi.CaffeineCachingProvider;
import com.github.benmanes.caffeine.jcache.configuration.CaffeineConfiguration;
import java.util.OptionalLong;
import java.util.concurrent.TimeUnit;
<%_ if (enableHibernateCache) { _%>
import org.hibernate.cache.jcache.ConfigSettings;
<%_ } _%>
<%_ } _%>
<%_ if (cacheProvider === 'redis') { _%>
import org.redisson.Redisson;
Expand Down Expand Up @@ -121,8 +113,7 @@ public class CacheConfiguration {

private void customizeCacheManager(CacheManager cm) {
<%_ if (!skipUserManagement || (authenticationType === 'oauth2' && databaseType !== 'no')) { _%>
createCache(cm, <%=packageName%>.repository.UserRepository.USERS_BY_LOGIN_CACHE);
createCache(cm, <%=packageName%>.repository.UserRepository.USERS_BY_EMAIL_CACHE);
createCache(cm, <%=packageName%>.repository.UserRepository.USERS_CACHE);
<%_ if (enableHibernateCache) { _%>
createCache(cm, <%=packageName%>.domain.User.class.getName());
createCache(cm, <%=packageName%>.domain.Authority.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import java.time.Instant;
public interface UserRepository extends JpaRepository<User, <% if (authenticationType !== 'oauth2') { %>Long<% } else { %>String<% } %>> {

<%_ if (usesCache) { _%>
public static String USERS_BY_LOGIN_CACHE = "usersByLogin";
public static String USERS_BY_EMAIL_CACHE = "usersByEmail";
public static String USERS_CACHE = "usersByLogin";
<%_ } _%>
<% if (authenticationType !== 'oauth2') { %>
Expand All @@ -45,17 +43,23 @@ public interface UserRepository extends JpaRepository<User, <% if (authenticatio

@EntityGraph(attributePaths = "authorities")
<%_ if (usesCache) { _%>
@Cacheable(cacheNames = "usersByLogin")
@Cacheable(cacheNames = USERS_CACHE)
<%_ } _%>
public Optional<User> findOneByLogin(String login);

@EntityGraph(attributePaths = "authorities")
<%_ if (usesCache) { _%>
@Cacheable(cacheNames = "usersByEmail")
@Cacheable(cacheNames = USERS_CACHE)
<%_ } _%>
public Optional<User> findOneByEmail(String email);

public Page<User> findAllByLoginNot(String login, Pageable pageable);
@EntityGraph(attributePaths = "authorities")
<%_ if (usesCache) { _%>
@Cacheable(cacheNames = USERS_CACHE)
<%_ } _%>
public Optional<User> findOneByLoginIgnoreCaseOrEmail(String login, String email);

public Page<User> findByLoginNotEqual(String login, Pageable pageable);

public void update(@Id <% if (authenticationType !== 'oauth2') { %>Long<% } else { %>String<% } %> id, Instant createdDate);
}
Loading

0 comments on commit c5b32ea

Please sign in to comment.