Devskiller / jpa2ddl

JPA Schema Generator Plugin
Apache License 2.0
110 stars 33 forks source link

Exampel of Use #17

Closed MiguelEcar closed 6 years ago

MiguelEcar commented 6 years ago

Hello, I am trying to integrate this lib into my project, but I could not manage to run. So, I would like to an example of use.. I want to generate db migrations for flyway, but when I try it.. nothing works...

thats is my pom.xml

<dependencies>
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
        <dependency>
            <groupId>com.devskiller.jpa2ddl</groupId>
            <artifactId>jpa2ddl-core</artifactId>
            <version>0.9.11</version>
        </dependency>
        <dependency>
            <groupId>com.devskiller.jpa2ddl</groupId>
            <artifactId>jpa2ddl-maven-plugin</artifactId>
            <version>0.9.11</version>
        </dependency>
        <dependency>
            <groupId>com.devskiller.jpa2ddl</groupId>
            <artifactId>jpa2ddl-parent</artifactId>
            <version>0.9.11</version>
            <type>pom</type>
        </dependency>
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>3.5.2</version>
        </dependency>
        <!--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-->

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.devskiller.jpa2ddl</groupId>
                <artifactId>jpa2ddl-maven-plugin</artifactId>
                <version>0.9.11</version>
                <configuration>
                    <outputPath>${basedir}/src/main/resources/db/migrations/</outputPath>
                    <packages>
                        <package>br.com.porthal.gadobom.entities</package>
                    </packages>
                    <jpaProperties>
                        <property>
                            <name>hibernate.dialect</name>
                            <value>org.hibernate.dialect.PostgreSQLDialect</value>
                        </property>
                    </jpaProperties>
                    <formatOutput>true</formatOutput>
                    <delimiter>;</delimiter>
                    <action>UPDATE</action>
                </configuration>
            </plugin>

        </plugins>
    </build>
</code>
jkubrynski commented 6 years ago

What do you mean my nothing works?

Please notice that to run it automatically without defining executions, you need to add <extensions>true</extensions> to your plugin. Exactly as in the readme

MiguelEcar commented 6 years ago

perfect.. my fault.. I have copied it from the example under "Generate migrations" session.. and it doesnt have this code true

but now I have other question. is it possible to generate sql migration from entities in an external jar from my WS application???

jkubrynski commented 6 years ago

@MiguelEcar it should work automatically -> did you tried to just include the package, assuming your jar is a maven dependency?

MiguelEcar commented 6 years ago

Yes I added, but it is not a problem... I manged to solve this by adding the plug in in the external lib pom.. and it worked fine.. thnk you