Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only dev and prod profiles work #166

Closed
agilob opened this issue Aug 24, 2020 · 9 comments · Fixed by #228
Closed

Only dev and prod profiles work #166

agilob opened this issue Aug 24, 2020 · 9 comments · Fixed by #228
Assignees
Labels
bug 🐞 Something isn't working

Comments

@agilob
Copy link
Contributor

agilob commented Aug 24, 2020

Overview of the issue

I'm trying to access swagger but noticed that only prod and dev profiles can be used. Starting app with -P dev,swagger starts only dev profile:

        Application 'jhipster' is running! Access URLs:
        Local:                  http://localhost:8080
        External:               http://localhost:8080
        Environment(s):         [dev]

Swagger-ui resource contains invalid content:

image

@atomfrede
Copy link
Member

You are using gradle? Can you try -Pdev -Pswagger ?

@agilob
Copy link
Contributor Author

agilob commented Aug 25, 2020

$./gradlew -Pdev -Pswagger
....
----------------------------------------------------------
        Application 'jhipster' is running! Access URLs:
        Local:                  http://localhost:8080
        External:               http://localhost:8080
        Environment(s):         [dev]

and the same result when visiting swagger-ui/index.html

@atomfrede
Copy link
Member

It is a bug. The dev config does not set micronaut environments at all while the prod config does still set the spring property.

@atomfrede atomfrede added the bug 🐞 Something isn't working label Aug 25, 2020
@atomfrede
Copy link
Member

Just to make sure, the flags on maven/gradle are mostly used for changing the build/packaging. But to support switching the environment via gradle properties you could do in profile_dev.gradle. I guess the more severe issue is, that when building with prod profile the environment is not compiled into the jar.

if (project.hasProperty("swagger")) {
    profiles += ",swagger"
}

tasks.withType(JavaExec) {
    classpath += configurations.developmentOnly
    jvmArgs('-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
    systemProperties(
        'micronaut.environments':profiles
    )
    if (gradle.startParameter.continuous) {
        systemProperties(
            'micronaut.io.watch.restart':'true',
            'micronaut.io.watch.enabled':'true',
            "micronaut.io.watch.paths":"src/main"
        )
    }
}

@atomfrede
Copy link
Member

I think the issue larger than I thought. We build the jar e.g. via -Pprod. This e.g. removes h2 and other dev dependencies from the jar. Starting the jar now fails as it tries to access the database via h2 (but depencies are missing). Setting the micronaut environment via system properties works just fine.

@JasonTypesCodes Correct my if thats wrong, but there is no property like spring.profiles.active to set the environment via properties. So I would propose to write the active profiles into a plain text file (e.g. environment) which is processed during the build to set the active profiles. This file is than read in the main method and set the environment accordingly, what do you think?

@JasonTypesCodes
Copy link
Contributor

micronaut.environments is the property you would use. They can also be set using an environment variable (MICRONAUT_ENVIRONMENTS) and in some cases passed in as a arg (-micronaut.environments).

More info here: https://docs.micronaut.io/latest/guide/index.html#environments

@atomfrede
Copy link
Member

We use either MICRONAUT_ENVIRONMENTS or micronaut.environments from system properties and set it in the application context builder. So I think we must read it from a third source in case neither the environment variable nor the system property is provided. Right now the code just uses dev if no environments are provided from the outside.

@agilob
Copy link
Contributor Author

agilob commented Aug 27, 2020

MICRONAUT_ENVIRONMENTS=dev,swagger ./mvnw

----------------------------------------------------------
        Application 'mhipster' is running! Access URLs:
        Local:                  http://localhost:8080
        External:               http://localhost:8080
        Environment(s):         [dev, swagger]
----------------------------------------------------------
./mvnw -Dmicronaut.environments=dev,swagger
----------------------------------------------------------
        Application 'agileb' is running! Access URLs:
        Local:                  http://localhost:8080
        External:               http://localhost:8080
        Environment(s):         [dev]
----------------------------------------------------------

profile needs to be set using env variable, maven -D doesnt work.

@atomfrede
Copy link
Member

Yes. Same for gradle right now, but see above how to extend the gradle file. Nevertheless when building the jar with prod profile it should use prod configuration out of box.

@atomfrede atomfrede self-assigned this Mar 5, 2021
atomfrede added a commit to atomfrede/generator-jhipster-micronaut that referenced this issue Mar 6, 2021
atomfrede added a commit to atomfrede/generator-jhipster-micronaut that referenced this issue Mar 6, 2021
atomfrede added a commit to atomfrede/generator-jhipster-micronaut that referenced this issue Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
3 participants