repaint-io / maven-tiles

Injecting maven configurations by composition rather than inheritance
154 stars 32 forks source link

Profiles defined inside tiles don't appear to work. #53

Open talios opened 8 years ago

akanter commented 8 years ago

Really? I have a profile working in my tile just fine...

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <properties>
        <version.maven.compiler.plugin>3.1</version.maven.compiler.plugin>
        <version.java>1.7</version.java>
        <crossCompileJavaArg></crossCompileJavaArg>
    </properties>
    <profiles>
        <profile>
            <activation>
                <jdk>[1.8,]</jdk>
            </activation>
            <properties>
                 <crossCompileJavaArg>-Xbootclasspath/p:${env.JAVA7_HOME}/jre/lib/</crossCompileJavaArg>
            </properties>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${version.maven.compiler.plugin}</version>
                <configuration>
                    <source>${version.java}</source>
                    <target>${version.java}</target>
                    <compilerArgs>
                        <arg>-Xlint:unchecked</arg>
                        <arg>${crossCompileJavaArg}</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
talios commented 8 years ago

Interesting, I don't have any <activiation> section in mine, leaving it up to the command line to request -Psomeprofile which doesn't seem to run. I had thought we'd fixed/tested that ages ago and it worked, maybe there's something else going on that's confusing my builds.

Tzrlk commented 8 years ago

I can't even get it to work when setting the environment variable that triggers the profile activation.

rvowles commented 8 years ago

Do you have a sample project for us to check @Tzrlk ?

stickycode commented 7 years ago

I have a sample project

mvn org.apache.maven.plugins:maven-release-plugin:2.3.2:perform -Ppromote-to-central -DconnectionUrl=scm:git:git@github.com:StickySource/sticky-tile-upload-nexus.git -Dtag=sticky-tile-upload-nexus-1.1

timothysparg commented 6 years ago

hi all

I've looked at this a little bit as we make use of profiles extensively.

I created a test project in a fork of your repo with a hack that seems to resolve the issue https://github.com/timothysparg/maven-tiles The changes I made to TilesMavenLifecycleParticipant.groovy seem to resolve the issue in with the example project that I was using (included as a sub folder)

If you guys could give me some pointers as to where in the lifecycle I should try and implement a solution, I will happily give it a bash - the changes I've made are more for an illustrative point than anything else

rvowles commented 6 years ago

your solution looks fine to me @timothysparg - is there a reason we shouldn't just use it?

timothysparg commented 6 years ago

@rvowles I just wasn't sure if that was the correct place in the project lifecycle to place the code.

I have created a submission via GerritHub If you're happy with it

timothysparg commented 6 years ago

Please hold on this - I was doing some checking on this this morning, and although I can now see the profiles use help:effective-pom, they still don't seem to activate

rvowles commented 6 years ago

ok. They may be appearing too late - Maven does variable resolution before it hits the lifecycle plugin, which is what makes using variables in versions painful. I suspect we may have to run the activation logic ourselves and merge them into the POM.

udalrich commented 6 years ago

With maven 3.5.0 and tiles 2.11, it appears that the profiles are activated, but maven gives a warning that they are unknown:

[WARNING] The requested profile "dev" could not be activated because it does not exist.

This is the last line of output from by build, even though the dev profile exists (inside a tile) and is activated.

If you can inject the profile into the pom model, that would probably fix that warning and also make the profile show up with help:effective-pom.

talios commented 6 years ago

@timothysparg Just pulled the review and ran it locally, and still see the warning being mentioned as @udalrich mentions, did you ever manage to resolve that at all?

timothysparg commented 6 years ago

No, I initially thought this would be a quick fix, but maven seems to handle profile evaluation differently to how it handles other sections of the pom.

I can't remember all the semantic issues right now, but I do remember that my pr did not resolve the issue satisfactorily

tchlyah commented 5 years ago

Do you have any news about this issue? Profiles aren't copied even in the latest version

rvowles commented 5 years ago

No, since it hasn't affected me I haven't looked at it. We do welcome PRs in case you'd like to attempt to figure out the deep dark depths of why Maven isn't passing this info on.

On Thu, Dec 6, 2018 at 5:03 AM Tayeb Chlyah notifications@github.com wrote:

Do you have any news about this issue? Profiles aren't copied even in the latest version

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/repaint-io/maven-tiles/issues/53#issuecomment-444539167, or mute the thread https://github.com/notifications/unsubscribe-auth/AADZ2EZaH3EiZSMeQtPLz7fWDmwpENi7ks5u1-5DgaJpZM4HW1O6 .

--

Richard Vowles, Full stack - from Kubernetes, through Node & Java, Web and Mobile development in Flutter - software developer for hire!

ph: +64275467747, web: www.google.com/+RichardVowles

talios commented 5 years ago

From my uses - profiles appear to copy and run as expected - EXCEPT that maven reports that the profile doesn't exist at the end of a build still - even tho it used it. @tchlyah are you seeing different behaviour or?

hackmann commented 5 years ago

I don't mind the warning as I normally do not select profiles explicitly but activate them based on system properties.

The problem I have is with compound tiles like java_library:

<?xml version="1.0" encoding="UTF-8"?>
<!--suppress MavenModelInspection -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <tiles>
    <tile>net.worldticket.build:profile_deploy_only:@project.version@</tile>
    <tile>net.worldticket.build:enforcer_dependencies:@project.version@</tile>
    <tile>net.worldticket.build:surefire:@project.version@</tile>
    <tile>net.worldticket.build:failsafe:@project.version@</tile>
    <tile>net.worldticket.build:jacoco_prepare:@project.version@</tile>
    <tile>net.worldticket.build:java_attach_sources:@project.version@</tile>
    <tile>net.worldticket.build:java_compiler:@project.version@</tile>
    <tile>net.worldticket.build:java_jar:@project.version@</tile>
  </tiles>
</project>

And then using it together with single tiles:

  <build>
    <plugins>
      <plugin>
        <groupId>io.repaint.maven</groupId>
        <artifactId>tiles-maven-plugin</artifactId>
        <!-- Added java test jar -->
        <configuration>
          <tiles>
            <tile>net.worldticket.build:java_library:${java_dependencies.version}</tile>
            <tile>net.worldticket.build:java_test_jar:${java_dependencies.version}</tile>
            <tile>net.worldticket.build:joda_beans_validate:${java_dependencies.version}</tile>
          </tiles>
        </configuration>
      </plugin>
    </plugins>
  </build>

I cannot get the profile from profile_deploy_only to affect any of the tiles listed directly in the project. It only affects the tiles listed together with it in the compound tile.

I guess this is because tiles are expanded breadth first and not depth first:

 mvn -DdeployOnly validate
[INFO] Scanning for projects...
[INFO] --- tiles-maven-plugin: Injecting 18 tiles as intermediary parent artifacts for net.worldticket.dcs:dcs-gateway...
[INFO] Mixed 'null:dcs-gateway:null' with tile 'net.worldticket.build:java_library:5.54.1-SNAPSHOT' as its new parent.
[INFO] Explicitly set groupId to 'net.worldticket.dcs' from original parent 'net.worldticket.dcs:dcs-parent:5.53.9-SNAPSHOT'.
[INFO] Explicitly set version to '5.53.9-SNAPSHOT' from original parent 'net.worldticket.dcs:dcs-parent:5.53.9-SNAPSHOT'.
[INFO] Mixed 'net.worldticket.build:java_library:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:java_test_jar:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:java_test_jar:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:joda_beans_validate:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:joda_beans_validate:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:profile_deploy_only:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:profile_deploy_only:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:enforcer_dependencies:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:enforcer_dependencies:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:surefire:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:surefire:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:failsafe:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:failsafe:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:jacoco_prepare:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:jacoco_prepare:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:java_attach_sources:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:java_attach_sources:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:java_compiler:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:java_compiler:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:java_jar:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:java_jar:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:enforcer_ban_dependencies:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:enforcer_ban_dependencies:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:enforcer_ban_test_dependencies:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:enforcer_ban_test_dependencies:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:enforcer_require_same_version:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:enforcer_require_same_version:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:failsafe_integration_test:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:failsafe_integration_test:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:failsafe_verify:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:failsafe_verify:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:jacoco_prepare_test:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:jacoco_prepare_test:5.54.1-SNAPSHOT' with tile 'net.worldticket.build:jacoco_prepare_verify:5.54.1-SNAPSHOT' as its new parent.
[INFO] Mixed 'net.worldticket.build:jacoco_prepare_verify:5.54.1-SNAPSHOT' with original parent 'net.worldticket.dcs:dcs-parent:5.53.9-SNAPSHOT' as its new top level parent.
[INFO] 

If I explicitly list profile_deploy_only as the first tile in the project

  <build>
    <plugins>
      <plugin>
        <groupId>io.repaint.maven</groupId>
        <artifactId>tiles-maven-plugin</artifactId>
        <!-- Added java test jar -->
        <configuration>
          <tiles>
            <tile>net.worldticket.build:profile_deploy_only:${java_dependencies.version}</tile>
            <tile>net.worldticket.build:java_library:${java_dependencies.version}</tile>
            <tile>net.worldticket.build:java_test_jar:${java_dependencies.version}</tile>
            <tile>net.worldticket.build:joda_beans_validate:${java_dependencies.version}</tile>
          </tiles>
        </configuration>
      </plugin>
    </plugins>
  </build>

then it works

lfvJonas commented 11 months ago

I got a little confused when we started using Maven Tiles, I got the same behaviour profiles work as expected but maven reports they do not exsist.

Is this how it's should behave?