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

Abiblity to default-build to attach its output executable binary to maven session #82

Closed
dantran opened this issue Feb 13, 2021 · 11 comments

Comments

@dantran
Copy link

dantran commented Feb 13, 2021

I have maven go build with has many maven modules, each module produce a go executable

Below the dependecyManagement where I disabel mvn-golang lifecycle and only enable default-build

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>com.igormaznitsa</groupId>
      <artifactId>mvn-golang-wrapper</artifactId>
      <executions>
        <!-- turn off default steps -->
        <!-- keep default-build -->
        <execution>
          <id>default-generate</id>
          <phase>none</phase>
        </execution>
        <execution>
          <id>default-fix</id>
          <phase>none</phase>
        </execution>
        <execution>
          <id>default-fmt</id>
          <phase>none</phase>
        </execution>
        <execution>
          <id>default-test</id>
          <phase>none</phase>
        </execution>
        <execution>
          <id>default-mvninstall</id>
          <phase>none</phase>
        </execution>
        <execution>
          <id>default-install</id>
          <phase>none</phase>
        </execution>
        <execution>
          <id>default-build</id>
          <configuration>
            <strip>${go.strip}</strip>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</pluginManagement>

I'd like to have the ability to add an additional setting at default-build configure to attach is build output to maven session.

I currently use maven-antrun-plugin to repeat each child module, like this

<plugins>

  <plugin>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>mvn-golang-wrapper</artifactId>
    <extensions>true</extensions>
    <configuration>
      <workingDir>${golang.src.dir}/${project.artifactId}</workingDir> <!--proprietary path -->
    </configuration>
  </plugin>

  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <id>attach-artifacts</id>
        <phase>package</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <target>
            <attachartifact file="${project.build.directory}/${project.build.finalName}" type="${exe.ext}" />
          </target>
        </configuration>
      </execution>
    </executions>
  </plugin>

</plugins>

Propose settings for build mojo

<attached>true</attache>
<type>xxxx</type>
<classifier>optional</optional>
@raydac
Copy link
Owner

raydac commented Feb 13, 2021

there is verbose flag for all goals and if you make it true then it will print output into log <verbose>true</verbose>, also you can turn on it through maven property mvn.golang.verbose

<mvn.golang.verbose>true</mvn.golang.verbose>

@raydac raydac self-assigned this Feb 13, 2021
@dantran
Copy link
Author

dantran commented Feb 13, 2021

@raydac i am not sure about verbose flag anything to do with my request having mvn-golang wrapper to attach the output binary to maven session for install/deploy purpose

@raydac
Copy link
Owner

raydac commented Feb 13, 2021

yes, looks like that I not correctly understood build output
and why do you use ANT task instead of Maven deploy plugin? it allows to deploy generated file with required parameters into maven repository and use it
or do you mean that you would like to include generated executable file into result artifact archive to be deployed into repository?

@dantran
Copy link
Author

dantran commented Feb 13, 2021

using ant:attachartifact is correct, it attaches the build artifact Maven so that my go binary will be installed ( to local repo) and deploy (to remote maven repo)

what I asking is to update https://github.com/raydac/mvn-golang/blob/master/mvn-golang-wrapper/src/main/java/com/igormaznitsa/mvngolang/GolangBuildMojo.java

then attach ${project.build.directory}/${project.build.finalName} to maven session for the same purpose

yes = "or do you mean that you would like to include generated executable file into result artifact archive to be deployed into repository?"

@raydac
Copy link
Owner

raydac commented Feb 13, 2021

from point of view of maven of course sounds a bit strange to include platform-depended artifact into resulted artifact but idea is good
I think it is no so good to provide such functionality by default but I will add special flag and property into mvn-golang build command to attach result artifact (if it is found after successful execution) into maven session artifacts, ok?

raydac added a commit that referenced this issue Feb 13, 2021
@raydac
Copy link
Owner

raydac commented Feb 13, 2021

I have added functionality into build mojo, now there are three more properties

  • attach - boolean (by default false) which allows turn on attach for built result file (or through property mvn.golang.build.attach)
  • attachType - string (by default bin) which allows define type for attached artifact (or through property mvn.golang.build.attach.type)
  • attachClassifier - string (by default none) which allows define classifier for attached artifact (or through property mvn.golang.build.attach.classifier)

@dantran
Copy link
Author

dantran commented Feb 13, 2021

@raydac awesome

@raydac
Copy link
Owner

raydac commented Feb 13, 2021

check snapshot pls and if all is ok then pls close the issue

@dantran
Copy link
Author

dantran commented Feb 13, 2021

it works. this saves a bunch of repeated antrun plugin block. Thanks

Looking forward to a new release

@dantran dantran closed this as completed Feb 13, 2021
@rbsrafa
Copy link

rbsrafa commented Mar 13, 2021

Hello, I've been testing with this plugin and so far it's amazing.
Regarding this chat, I could get the binary into the generated maven folder, but I'd like to generate it without an extension.
E.g. instead of my-bin.bin -> just my-bin.
I tried to provide a blank attachType but I could see in the src code that it defaults to "bin" if not is provided. Would it be possible to leave the default as an empty string and then provided the desired extension if needed? Thanks

@raydac
Copy link
Owner

raydac commented Mar 14, 2021

@rbsrafa
attachType is for artifact installation, could you drop example of your pom? do you want generate artifact in repository without type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants